Capturing an optional second group of digits (not repeating) using a regular expression
I have a huge dataset where I am trying to extract a group of 4 digits. The problem is that sometimes there will be a 4-digit preceding group which I don't want. These two groups will never be the same with each other.
Example:
String String 7777 Some more string
String 1234 7777 Some more string
In both cases, I want to extract ONLY 7777
(or any combination of numbers replaces it). There is no picture to tell which group of numbers will be in which position - any number from 0000 to 9999 can be in the first or second position.
If it were possible, I think he will do what I want?
\b\d{4}{0,1}\s{0,1}(\d{4})\b
Extra 4 digits, extra space, 4 digits. But I tried this and some variations of it, but I cannot get it to work!
Looking ahead seems like a likely candidate, but I don't understand how to build a template.
source to share