Regular Expressions 101

Community Library Entry

0

Regular Expression
PCRE2 (PHP >=7.3)

/
\b([A-Z]{2})[^A-Z0-9]*?([0-9]{1,2})[^A-Z0-9]*?([A-Z]{0,3})[^A-Z0-9]*?([0-9]{4})\b
/
gi

Description

  • lenient validator (for transformation)
    • /\b([A-Z]{2})[^A-Z0-9]*?([0-9]{1,2})[^A-Z0-9]*?([A-Z]{0,3})[^A-Z0-9]*?([0-9]{4})\b/i
    • Matches 4 groups like:
        1. RJ
        1. 02
        1. FG
        1. 5343
    • Will match:
      • RJ03QH3918
      • RJ 03QH 3918
      • RJ-03-QH-3918
      • MP,,,03-QH3998
    • Will not match:
      • MP,,01,03-QH3998
      • MP03QH399998
Submitted by Birla - 2 years ago (Last modified 2 years ago)