Regular Expressions 101

Community Library

Community Library Entry

0

Regular ExpressionOpen Workspace

/
([0-7]\d{2}(" "|-|\.)?\d{2}(?(2)(" "|-|\.))\d{4})
/
gm

Description
Created·2023-03-11 14:47
Type·Match
Flavor·PCRE2 (PHP)

([0-7]\d{2}(" "|-|.)?\d{2}(?(2)(" "|-|.))\d{4})

  • Finds the first number as 0-7 then matches the next two digits
  • Will check what delimitator (group 2) if any is used
  • finds two digits
  • if a delimitator is used - if it is then use one here, if not then don't (prevents US based zip code + 4 from getting caught up)
  • finds four digits

Additional tweaks can be made to make it more efficient - this works for me for now.

Submitted by ACCS
Open Workspace