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
/
(\A|[^[])\[{2}[^[](?<content>[^]]+)[^]]\]{2}([^]]|\z)
/
gs
1st Capturing Group
(\A|[^[])
1st Alternative
\A
\A asserts position at start of the string
2nd Alternative
[^[]
Match a single character not present in the list below
[^[]
[ matches the character [ with index 9110 (5B16 or 1338) literally (case sensitive)
\[
matches the character [ with index 9110 (5B16 or 1338) literally (case sensitive)
{2} matches the previous token exactly 2 times
Match a single character not present in the list below
[^[]
[ matches the character [ with index 9110 (5B16 or 1338) literally (case sensitive)
Named Capture Group content
(?<content>[^]]+)
Match a single character not present in the list below
[^]]
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
] matches the character ] with index 9310 (5D16 or 1358) literally (case sensitive)
Match a single character not present in the list below
[^]]
] matches the character ] with index 9310 (5D16 or 1358) literally (case sensitive)
\]
matches the character ] with index 9310 (5D16 or 1358) literally (case sensitive)
{2} matches the previous token exactly 2 times
3rd Capturing Group
([^]]|\z)
1st Alternative
[^]]
Match a single character not present in the list below
[^]]
] matches the character ] with index 9310 (5D16 or 1358) literally (case sensitive)
2nd Alternative
\z
\z asserts position at the end of the string
Global pattern flags
g modifier: global. All matches (don't return after first match)
s modifier: single line. Dot matches newline characters
Your regular expression does not match the subject string.Try launching the debugger to find out why.

Regular Expression
No Match

/
/
gs

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