问题
I'm trying to match the last name of a value of an ini line.
foo.bar.far.boo = "some value"
I can match 'boo =' but I just need 'boo'
I do (\w+)\s*=
but it matches the equal signs, but I don't want it to be matched.
By the way, I should be able to get if there is no sub values like :
foo = "value"
回答1:
Use
\w+(?=\s*=)
(?=...)
is a positive lookahead assertion, meaning "assert that the enclosed regex can be matched here, but don't make it part of the match itself".
So the regex matches one or more alphanumeric characters if and only if they are followed by (optional whitespace and) an equals sign.
来源:https://stackoverflow.com/questions/5070558/regex-to-match-ini-value