Regular Expressions 101

Save & Share

  • Save Regex
    ctrl+s
  • Update Regex
    ctrl+⇧+s

Flavor

  • PCRE2 (PHP >=7.3)
  • PCRE (PHP <7.3)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java 8

Function

  • Match
  • Substitution
  • List
  • Unit Tests
/
([afd]?)(((p[\s\.]?[o\s][\.]?)\s?)|(post\s?office\s?))((box|bin|b\.?)?\s?(num|number|#)?\s?\d+)
/
ig
1st Capturing Group
([afd]?)
Match a single character present in the list below
[afd]
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
afd
matches a single character in the list afd (case insensitive)
2nd Capturing Group
(((p[\s\.]?[o\s][\.]?)\s?)|(post\s?office\s?))
1st Alternative
((p[\s\.]?[o\s][\.]?)\s?)
3rd Capturing Group
((p[\s\.]?[o\s][\.]?)\s?)
4th Capturing Group
(p[\s\.]?[o\s][\.]?)
p matches the character p with index 11210 (7016 or 1608) literally (case insensitive)
Match a single character present in the list below
[\s\.]
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
\s matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
\. matches the character . with index 4610 (2E16 or 568) literally (case insensitive)
Match a single character present in the list below
[o\s]
o matches the character o with index 11110 (6F16 or 1578) literally (case insensitive)
\s matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
Match a single character present in the list below
[\.]
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
\. matches the character . with index 4610 (2E16 or 568) literally (case insensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
2nd Alternative
(post\s?office\s?)
5th Capturing Group
(post\s?office\s?)
post
matches the characters post literally (case insensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
office
matches the characters office literally (case insensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
6th Capturing Group
((box|bin|b\.?)?\s?(num|number|#)?\s?\d+)
7th Capturing Group
(box|bin|b\.?)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
1st Alternative
box
box
matches the characters box literally (case insensitive)
2nd Alternative
bin
bin
matches the characters bin literally (case insensitive)
3rd Alternative
b\.?
b matches the character b with index 9810 (6216 or 1428) literally (case insensitive)
\.
matches the character . with index 4610 (2E16 or 568) literally (case insensitive)
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
8th Capturing Group
(num|number|#)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
1st Alternative
num
num
matches the characters num literally (case insensitive)
2nd Alternative
number
number
matches the characters number literally (case insensitive)
3rd Alternative
#
# matches the character # with index 3510 (2316 or 438) literally (case insensitive)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
\d
matches a digit (equivalent to [0-9])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
Global pattern flags
i modifier: insensitive. Case insensitive match (ignores case of [a-zA-Z])
g modifier: global. All matches (don't return after first match)
Your regular expression does not match the subject string.

Regular Expression
No Match

/
/
ig

Test String