I am working on some regex and I wonder why this regex
"(?<=(.*?id(( *)=)\\s[\"\']))g"
does not match the string
<input id = "g" />
in Java?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Not only does Java not allow unbounded lookbehind, it’s supposed to throw an exception if you try. The fact that you’re not seeing that exception is itself a bug.
You shouldn’t be using lookbehind for that anyway. If you want to match the value of a certain attribute, the easiest, least troublesome approach is to match the whole attribute and use a capturing group to extract the value. For example:
Output:
Do yourself a favor and forget about lookbehinds for a while. They’re tricky even when they’re not buggy, and they’re really not as useful as you might expect.