Regex ignore match if contained within 23 digit string
I'm having a problem coming with a solution to a situation, I have this regex to match an specific digit sequence:
(102030)\d{10}Using this as a test data, i get the following matches:
75277887243040354513001
55345377243014107206375
810203087654135168 <- Match
1102030698798798477 <- Match
71020307248040361799581 <- MatchWhat I'm trying to do is ignore cases where there are 23 digits on the string, is that possible using only regex? I've tried with negative look ahead but haven't been able to achieve it.
2 Answers
For look ahead you need something before it - so let start with
\dThen by negative ahead of the next 22 digits:
(?!\d{22})we filter out all lines with 23 digits. Then may follow your original string
(102030)\d{10}So the full regular expression will be
\d(?!\d{22})(102030)\d{10}See the result at regex101.com:
\b(?!\d{23}\b)\d*((102030)\d{10})\d*\bThis captures the match in its first subgroup.
1