I am new to regex, and I am trying to break down the regex so I can understand it better:
/(\d{3})(?=\d)/
I understand that (\d{3})
is capturing 3 digits, but unsure what the second portion is trying to capture.
What does ?=
mean?
(?=\d)
is a positive lookahead it means match & capture 3 digits that are followed by a digit.
So something like this will happen:
1234 => capture 123
123a => no match
(?=pat)
- Positive lookahead assertion: ensures that the following characters match pat, but doesn't include those characters in the matched text
/(\d{3})(?=\d)/
- Here (\d{3})
is capturing 3 digits, followed by a digit,but last digit not to be captured in that group.
Look here, here and here
Hope this will help!
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