N
N
nazgul2011-08-17 17:21:58
Regular Expressions
nazgul, 2011-08-17 17:21:58

Regular expression

Hello. There is a regular expression:
^(?:(?!039|050|063|066|067|068|091|092|093|094|095|096|097|098|099|00).)*$
Its task is in order not to miss calls to numbers of mobile operators in Ukraine and abroad (00).
The problem is that, among other things, calls do not go through to numbers in the body of which the specified substrings occur. For example, the call does not go through to the number 039 5420245, which is good, but it will not go through to the number 0445421 067 either .

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
GreenPeace, 2011-08-17
@GreenPeace

The problem is the following (for convenience, I'll shorten your long or to one option):
^(?:(?!00).)*$
The check (?! ...) is inside the group with the * sign, that is, it is performed every time when the reg Exp engine jumps to the next character. For your case, this check should be taken out of the group (and the brackets of the group should be removed altogether - since only 1 element will remain in it):
^(?!00).*$

D
Dmitry, 2011-08-17
@Neir0

Why use regular expressions for this? I guess it's easier and faster to check with string functions

A
Anatoly, 2011-08-17
@taliban

"0395420245".match(/^(?:039|050|063|066|067|068|091|092|093|094|095|096|097|098|099|00).*$/)
Don't do lookahead if using full line

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question