Reputation: 15477
(?<=atr1=\").*(?=\")
<h1 atr1="test1" atr2="test2"
I'm expecting regex to grab the value in atr1, but it is grabbing more than that. It stops at double quote after test2?
Upvotes: 0
Views: 45
Reputation: 29511
If you want to grab
test1
from
<h1 atr1="test1" atr2="test2"
then:
atr1="([^"]+)"
will capture it.
Upvotes: 2
Reputation: 786146
Use negation regex and avoid lookahead:
(?<=atr1=")[^"]+
However if you're using a language like PHP, Python, etc then I suggest avoiding regex altogether and use builtin DOM parsers instead.
Upvotes: 1
Reputation: 6272
Use the lazy modifier *?
to stop at the first double quote:
(?<=atr1=").*?(?=")
PS: i removed also the escaping for double quotes not strictly needed (unless you have to use a double quoted string)
Upvotes: 2