0
<input name="so and so" id="john doe" value="something something" />

I want to match only the space character that is within the " of a value= attribute.

I came up with this:

value="[^"',:<>/\r\n]*[ ][^"',:<>/\r\n]*"

Problem is this matches the whole string, where I just need the space in the matched string from above.

I am reading some tutorials, which leads me to think I need to use a conditional statement, but I can't seem to figure out how that would work. My guess (which of course didn't work) was:

(?(?=value="[^"',:<>/\r\n]*[^"',:<>/\r\n]*")[ ])

Any help is appreciated. Thanks!

David Avellan
  • 385
  • 4
  • 24

1 Answers1

1
\bvalue="\K|\G(?!^)[^"]*?\K\s+

You can use this to find spaces which are in value=" and before closing ".See demo.

https://regex101.com/r/lR1eC9/11

EDIT:

(?:(?<=\bvalue=")|\G(?!^))[^"]*?\K\s+(?=[^"=]*")

See demo.

https://regex101.com/r/lR1eC9/13

vks
  • 67,027
  • 10
  • 91
  • 124