Why following return ["vddv"]
instead of ["dd"]:
"aaavddv".match(/(?:v).*(?:v)/)
(?:v) # matches 'v' this is a non-capturing group, not a lookbehind
.* # matches 'dd'
(?:v) # matches 'v' this is a non-capturing group, not a lookahead
Non-capturing groups still participate in the match. Perhaps you want a lookahead/behind? But Javascript does not support lookbehind.
"aaavddv".match(/(?:v)(.*)(?:v)/)[1]
the whole match is correctly vddv
but if you want to match only dd
you need to use a capturing group (and look at element [1]
)
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