1

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 <- Match 

What 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 2

1

For look ahead you need something before it - so let start with

\d 

Then 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:

enter image description here

0
\b(?!\d{23}\b)\d*((102030)\d{10})\d*\b 

This captures the match in its first subgroup.

1
  • 1
    Consider adding further context Commented Sep 22, 2017 at 16:16

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.