-1

The regex that works with PCRE2 is the following:

<svg(?:\s+viewBox="(?<viewBox>[^"]+)"|\s+width="(?<width>[^"]+)"|\s+height="(?<height>[^"]+)"|\s+[^"]+="(?:[^"]+)")+>

Test string:

<svg fill-rule="evenodd" fill-rule="evenodd" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" fill-rule="evenodd" width="211" fill-rule="evenodd" height="61" fill-rule="evenodd">

regex101 link: https://regex101.com/r/Kje49r/1

Bee
  • 1
  • 1
    JavaScript's regex does not support named capture groups. What is the intention with using your current regex? – Tim Biegeleisen Jun 03 '22 at 04:04
  • You shouldn't be using regular expressions to try to parse xml – Shawn Jun 03 '22 at 05:52
  • There is no way to solve it like this in an ECMAScript regex flavor as with each capture, the group value is set to an empty string. You will need to use some code logic here, so it is best to pass straight to DOM parsing approach. – Wiktor Stribiżew Jun 03 '22 at 07:12

0 Answers0