What does the regular expression (\ d {3}) (? = \ D) mean?

I am new to regex and am trying to break up regex to better understand it:

 /(\d{3})(?=\d)/ 

I understand that it (\d{3})writes 3 digits, but I'm not sure what the second part is trying to capture.

What does it mean ?=?

+4
source share
2 answers

(?=\d)is a positive look , it means matching and capturing 3 digits followed by a digit.

So something like this will happen:

1234 => capture 123
123a => no match
+8
source

(?=pat) - A positive lookahead statement: ensures that the following characters match pat, but do not include these characters in matched text

/(\d{3})(?=\d)/ - (\d{3}) 3 , , .

,

, !

+2

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


All Articles