RegEx Lack

Why should you return ["vddv"] instead of ["dd"]:

 "aaavddv".match(/(?:v).*(?:v)/) 
+4
source share
3 answers
 (?: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 

Groups that are not participating in the capture are still participating in this match. Maybe you need a look? But Javascript does not support lookbehind.

+4
source
 "aaavddv".match(/(?:v)(.*)(?:v)/)[1] 

the whole match is correct vddv , but if you want to combine only dd , you need to use the capture group (and look at element [1] )

+3
source

/(?:v).*(?:v)/ indicates the expression v (number of characters) v

+3
source

Source: https://habr.com/ru/post/1413941/


All Articles