Home > Back-end >  How To Ignore An Character With Random Numbers Using RegEx?
How To Ignore An Character With Random Numbers Using RegEx?

Time:10-29

I am trying to ignore the character @ with random numbers combined using RegEx.

This is what I don't want to detect:
@1235

This is what I want to detect:
12345

This what I did so far:

(?!@[0-9])([0-9])

CodePudding user response:

You can use

(?<![@\d])\d 

See the enter image description here

CodePudding user response:

You want to assert that there is no @ to the left with a negative lookbehind (?<! instead of a negative lookahead (?!

\b(?<!@)\d 

Explanation

  • \b A word boundary to prevent a partial word match
  • (?<!@) Negative lookbehind, assert not @ to the left
  • \d Match 1 digits

Regex demo

  • Related