user3366906
user3366906

Reputation: 149

Regex and not condition

I have below two regex expressions

I want to say A and NOT B. How can I do that.

Thanks in advance for any help.

Upvotes: 0

Views: 106

Answers (1)

Gurmanjot Singh
Gurmanjot Singh

Reputation: 10360

Try this:

^(?!599999\d{10})\d{13,16}$

Click for Demo

Explanation:

  • ^ - asserts the start of the string
  • (?!599999\d{10})- negative lookahead to validate that the string does not start with 599999 followed by 10 digits
  • \d{13,16} - matches 13 to 16 digits
  • $ - asserts the end of the string

Edit:

If these numbers are in the same line, you can use this instead \b(?!599999\d{10})\d{13,16}\b

Upvotes: 1

Related Questions