So I want to match something like this -
foo <TEST>something something </TEST> blah
I want a regex that gets me the foo, but does not get me the something. I was thinking of using a regex that was something like this
(\w\s)<
with a negative lookahead, but I'm not sure how to use that in this case.
OTHER CASES-
something something foo <TEST> something something </TEST> blah
You could try something like this:
\w+(?=\s*<[^/])
regex101 demo
The positive lookahead (?=\s*<[^/])
ensures that there are optional spaces followed by a <
which is not followed by a /
ahead.
\w+ matches one or more \w
(?= beginning of positive lookahead
\s* optional spaces
< a < character
[^/] not a / character
) end of positive lookahead
Negetive look-ahead will do just fine.
(\S+)\s*<(?!/)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With