Home > Enterprise >  Regular Expression for identity number in office 365
Regular Expression for identity number in office 365

Time:10-05

I'm currently creating a custom regex for kenyan ID numbers, usually the ID number consists of eight digits, the first two digits is constant, but changes with time. Example of an ID number: 34640970. So the mentioned ID is within 34 series.

Other series is: 20 series 20456880, 20337228, 20656902 32 series 32879776, 32877009, 32344112 34 series 34640970, 34434229, 34223007

Have managed to write the following regex to be used by office 365 DLP for 34 series, but its not working. ^(\d{3,4})\d{8}

CodePudding user response:

You can use

\b(?:34|32|20)[0-9]{6}\b
(?<!\d)(?:34|32|20)[0-9]{6}(?!\d)

See the regex demo. Details:

  • \b - word boundary / (?<!\d) - a left-hand numeric boundary
  • (?:34|32|20) - a non-capturing group matching either 34, 32 or 20 (you can factor it in as (?:3[42]|20))
  • [0-9]{6} - six digits
  • \b - word boundary / (?!\d) - a right-hand numeric boundary.
  • Related