Regular Expressions 101

Save & Share

Flavor

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

Function

  • Match
  • Substitution
  • List
  • Unit Tests
@
\b(?:UG \(haftungsbeschränkt\)|(?:gG|g|Gesellschaft )?mbH|GbR|OHG|[KUeA]G|(?:g|Inv)AG|KGaA|e..?v..?|Limited|Stiftung|PartG(?: mbB)?|Partenreederei|Eigenbetrieb|Einzelunternehmen|Regiebetrieb|VVaG|SC?E|[AK]öR|Reit-AG)\s*(?:\&\s*Co.\s*(?:KGa?A?|OHG))?\b
@
gmusi
\b assert position at a word boundary: (^\w|\w$|\W\w|\w\W)
Non-capturing group
(?:UG \(haftungsbeschränkt\)|(?:gG|g|Gesellschaft )?mbH|GbR|OHG|[KUeA]G|(?:g|Inv)AG|KGaA|e..?v..?|Limited|Stiftung|PartG(?: mbB)?|Partenreederei|Eigenbetrieb|Einzelunternehmen|Regiebetrieb|VVaG|SC?E|[AK]öR|Reit-AG)
1st Alternative
UG \(haftungsbeschränkt\)
UG
matches the characters UG literally (case insensitive)
\( matches the character ( with index 4010 (2816 or 508) literally (case insensitive)
haftungsbeschränkt
matches the characters haftungsbeschränkt literally (case insensitive)
\) matches the character ) with index 4110 (2916 or 518) literally (case insensitive)
2nd Alternative
(?:gG|g|Gesellschaft )?mbH
Non-capturing group
(?:gG|g|Gesellschaft )?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
1st Alternative
gG
gG
matches the characters gG literally (case insensitive)
2nd Alternative
g
g matches the character g with index 10310 (6716 or 1478) literally (case insensitive)
3rd Alternative
Gesellschaft
Gesellschaft
matches the characters Gesellschaft literally (case insensitive)
mbH
matches the characters mbH literally (case insensitive)
3rd Alternative
GbR
GbR
matches the characters GbR literally (case insensitive)
4th Alternative
OHG
OHG
matches the characters OHG literally (case insensitive)
5th Alternative
[KUeA]G
Match a single character present in the list below
[KUeA]
KUeA
matches a single character in the list KUeA (case insensitive)
G matches the character G with index 7110 (4716 or 1078) literally (case insensitive)
6th Alternative
(?:g|Inv)AG
Non-capturing group
(?:g|Inv)
1st Alternative
g
g matches the character g with index 10310 (6716 or 1478) literally (case insensitive)
2nd Alternative
Inv
Inv
matches the characters Inv literally (case insensitive)
AG
matches the characters AG literally (case insensitive)
7th Alternative
KGaA
KGaA
matches the characters KGaA literally (case insensitive)
8th Alternative
e..?v..?
e matches the character e with index 10110 (6516 or 1458) literally (case insensitive)
. matches any character, including unicode
.
matches any character, including unicode
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
v matches the character v with index 11810 (7616 or 1668) literally (case insensitive)
. matches any character, including unicode
.
matches any character, including unicode
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
9th Alternative
Limited
Limited
matches the characters Limited literally (case insensitive)
10th Alternative
Stiftung
Stiftung
matches the characters Stiftung literally (case insensitive)
11th Alternative
PartG(?: mbB)?
PartG
matches the characters PartG literally (case insensitive)
Non-capturing group
(?: mbB)?
12th Alternative
Partenreederei
13th Alternative
Eigenbetrieb
14th Alternative
Einzelunternehmen
15th Alternative
Regiebetrieb
16th Alternative
VVaG
17th Alternative
SC?E
18th Alternative
[AK]öR
19th Alternative
Reit-AG
\s
matches any kind of invisible character (equivalent to [\p{Z}\h\v])
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
Non-capturing group
(?:\&\s*Co.\s*(?:KGa?A?|OHG))?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
\& matches the character & with index 3810 (2616 or 468) literally (case insensitive)
\s
matches any kind of invisible character (equivalent to [\p{Z}\h\v])
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
Co
matches the characters Co literally (case insensitive)
. matches any character, including unicode
\s
matches any kind of invisible character (equivalent to [\p{Z}\h\v])
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
Non-capturing group
(?:KGa?A?|OHG)
1st Alternative
KGa?A?
KG
matches the characters KG literally (case insensitive)
a
matches the character a with index 9710 (6116 or 1418) literally (case insensitive)
A
matches the character A with index 6510 (4116 or 1018) literally (case insensitive)
2nd Alternative
OHG
OHG
matches the characters OHG literally (case insensitive)
\b assert position at a word boundary: (^\w|\w$|\W\w|\w\W)
Global pattern flags
g modifier: global. All matches (don't return after first match)
m modifier: multi line. Causes ^ and $ to match the begin/end of each line (not only begin/end of string)
u modifier: unicode. Pattern strings are treated as UTF-16. Also causes escape sequences to match unicode characters
s modifier: single line. Dot matches newline characters
i modifier: insensitive. Case insensitive match (ignores case of [a-zA-Z])
Your regular expression does not match the subject string.Try launching the debugger to find out why.

Regular Expression
No Match

@
@
gmusi

Test String

Code Generator

Generated Code

Loading code sample...
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report.
For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php