tags:

views:

44

answers:

5

tax

V1

/([67]\d{10})|([67]\d{9})/

V2

/[67]\d{9,10}/

RegexBuddy highlights the second and third test records, but also portions of the first and last.

6777777777777777777
6777777777
7777777777
77777777777777

Is it possible to only match the exact matches?

+1  A: 

Try matching word boundaries.

\<[67][0-9]\{9,10\}\>
retracile
+3  A: 

You could use the anchors ^ and $ to match the start and end of the string/line:

^[67]\d{9,10}$

Or \b to mark the word boundaries:

\b[67]\d{9,10}\b
Gumbo
+1  A: 

Well, you should have included some information about the context in which you're using the regexp, but the common way is to include boundary matchers:

^[67]\d{9,10}$
Daniel Rinser
+1  A: 

What's separating your numbers? You can use a word boundary like this:

\b[67]\d{9,10}\b

Or whitespace, like this

\s[67]\d{9,10}\s

IRBMe
+1  A: 

I think you want to use word boundaries: http://www.regular-expressions.info/wordboundaries.html

AaronLS