Reputation: 21
currently I'm using such regex "(\d{4}\b)"
in order to extract the numbers.
Test string "test 125456 b", so the extract result is "5456".
I wish to get the same result "5456" under the string "test125456b".
I tried to use following regex
((?<!\d)(\d{4})(?!\d))
but it works if only 4 digits (not more) are noted between letters.
So, the aim is:
Upvotes: 1
Views: 11588
Reputation: 174826
To get the last four digits.
\d{4}(?=\D*$)
\d{4}
match the four digit character.(?=\D*$)
Only if the four digits are followed by a zero or more non-digit characters and the end of the line boundary.Upvotes: 1