I am trying to split the d attribute into a path tag in the svg file in tokens.
This is relatively easy:
d = "M 2 -12 C 5 15 21 19 27 -2 C 17 12 -3 40 5 7" tokens = d.split(/[\s,]/)
But this is also a valid d attribute:
d = "M2-12C5,15,21,19,27-2C17,12-3,40,5,7"
Complex parts are letters and numbers that are no longer separated, and negative numbers use only the negative sign as a separator. How to create a regex that handles this?
The rules look like this:
- splits wherever there is a space or a comma
- splitting numbers from letters (and save "-" with numbers)
I know I can use lookaround, for example:
tokens = pathdef.split(/(?<=\d)(?=\D)|(?<=\D)(?=\d)/)
I have a problem with the formation of one regular expression, which also splits on the minus signs and saves the minus sign with numbers.
The above code should be labeled as follows:
[ 'M', '2', '-12', 'C', '5', '15', '21', '19', '27', '-2', 'C', '17', '12', '-3', '40', '5', '7' ]