Reputation: 10264
I'm trying to create a regex which will match anything which looks like a phone number. If there's more than one number in a string, match both of them. A phone number is defined as:
N
, but can end in other letters/wordsSo I'd like to match these:
And disallow these:
I've toyed with negative lookahead/lookbehind but I can't get anything intelligible out. Is tis even possible or shall I do it in a higher language like .NET?
Upvotes: 0
Views: 147
Reputation: 336448
(?:\d\s*){10,}(?![\d\s]*N)
will match a 10+ digit phone number within a longer string, as long as that number is not followed by N
. It allows any number of spaces between each digit.
If all your phone numbers always start with 0
as in your example, you can explicitly code that into the regex:
\b0\s*(?:\d\s*){9,}(?![\d\s]*N)
Upvotes: 1