Regular Expressions 101

Save & Share

  • Regex Version: ver. 44
  • Update Regex
    ctrl+⇧+s
  • Save new Regex
    ctrl+s
  • Add to Community Library

Flavor

  • PCRE2 (PHP >=7.3)
  • PCRE (PHP <7.3)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java 8
  • .NET 7.0 (C#)
  • Rust
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests

Tools

Sponsors
There are currently no sponsors. Become a sponsor today!
An explanation of your regex will be automatically generated as you type.
Detailed match information will be displayed here automatically.
  • All Tokens
  • Common Tokens
  • General Tokens
  • Anchors
  • Meta Sequences
  • Quantifiers
  • Group Constructs
  • Character Classes
  • Flags/Modifiers
  • Substitution
  • A single character of: a, b or c
    [abc]
  • A character except: a, b or c
    [^abc]
  • A character in the range: a-z
    [a-z]
  • A character not in the range: a-z
    [^a-z]
  • A character in the range: a-z or A-Z
    [a-zA-Z]
  • Any single character
    .
  • Alternate - match either a or b
    a|b
  • Any whitespace character
    \s
  • Any non-whitespace character
    \S
  • Any digit
    \d
  • Any non-digit
    \D
  • Any word character
    \w
  • Any non-word character
    \W
  • Non-capturing group
    (?:...)
  • Capturing group
    (...)
  • Zero or one of a
    a?
  • Zero or more of a
    a*
  • One or more of a
    a+
  • Exactly 3 of a
    a{3}
  • 3 or more of a
    a{3,}
  • Between 3 and 6 of a
    a{3,6}
  • Start of string
    ^
  • End of string
    $
  • A word boundary
    \b
  • Non-word boundary
    \B

Regular Expression

/
/
gm

Test String

Code Generator

Generated Code

$re = '/(?=\{Infobox)(\{([^{}]|(?1))*\})/m'; $str = ' <?xml version="1.0"?><api><query><pages><page pageid="5843419" ns="0" title="France"><revisions><rev contentformat="text/x-wiki" contentmodel="wikitext" xml:space="preserve">{{about|the country}} {{Use dmy dates|date=November 2013}} {{EngvarB|date=November 2013}} {{see also|Portal:France{{!}}France portal|Outline of France}} {{pp-semi|small=yes}}{{pp-move-indef}} {{Infobox country |conventional_long_name = French Republic |native_name = {{native name|fr|République française|icon=no}} |common_name = France |image_flag = Flag of France.svg |demonym = French |government_type = [[Unitary state|Unitary]] [[Semi-presidential system|semi-presidential]] [[republic|constitutional republic]] |leader_title1 = [[President of France|President]] |leader_name1 = [[François Hollande]] |calling_code = [[Telephone numbers in France|+33]]{{refn|group=note|name=eleven|The overseas regions and collectivities form part of the [[French telephone numbering plan]], but have their own country calling codes: [[Guadeloupe]] +590; [[Martinique]] +596; [[French Guiana]] +594, [[Réunion]] and [[Mayotte]] +262; [[Saint Pierre and Miquelon]] +508. The overseas territories are not part of the French telephone numbering plan; their country calling codes are: [[New Caledonia]] +687, [[French Polynesia]] +689; [[Wallis and Futuna]] +681.}} |ISO_3166-1_alpha2 = |ISO_3166-1_alpha3 = FRA |ISO_3166-1_numeric = |sport_code = FRA |vehicle_code = F |cctld = [[.fr]]{{refn|group=note|name=ten|In addition to [[.fr]], several other Internet TLDs are used in French overseas \'\'départements\'\' and territories: [[.re]], [[.mq]], [[.gp]], [[.tf]], [[.nc]], [[.pf]], [[.wf]], [[.pm]], [[.gf]] and [[.yt]]. France also uses [[.eu]], shared with other members of the European Union. The [[.cat]] domain is used in [[Catalan Countries|Catalan-speaking territories]].}} }} \'\'\'France\'\'\' ({{IPAc-en|UK|ˈ|f|r|ɑː|n|s}}; {{IPAc-en|US|audio=en-us-France.ogg|ˈ|f|r|æ|n|s}}; {{IPA-fr|fʁɑ̃s|lang|France.ogg}}), officially the \'\'\'French Republic\'\'\' ({{lang-fr|link=no|République française}} {{IPA-fr|ʁepyblik fʁɑ̃sɛz|}}), is a sovereign country in [[Western Europe]] that includes [[Overseas departments and territories of France|overseas regions and territories]].{{refn|group=note|name=twelve|[[French Guiana]] is located in [[South America]]; [[Guadeloupe]] and [[Martinique]] are in the [[Caribbean]]; and [[Réunion]] and [[Mayotte]] are in the [[Indian Ocean]], off the coast of [[Africa]]. All five [[Administrative divisions of France#Overseas|are considered integral parts of the republic]].}} [[Metropolitan France]] extends from the [[Mediterranean Sea]] to the [[English Channel]] and the [[North Sea]], and from the [[Rhine]] to the [[Atlantic Ocean]]. It is one of only three countries (besides [[Morocco]] and [[Spain]]) to have both Atlantic and Mediterranean coastlines. Due to its shape, it is often referred to in French as \'\'{{lang|fr|l’Hexagone}}\'\' (&quot;The [[Hexagon]]&quot;). France is the largest country in [[Western Europe]] and the [[European Union]], and the third-largest in Europe as a whole. With a total population of around 66 million, it is the [[List of European countries by population|third most-populous]] European country. France is a [[Unitary state|unitary]] [[Semi-presidential system|semi-presidential]] [[republic]] with its [[Capital city|capital]] in [[Paris]], the nation\'s largest city and the main cultural and commercial centre. The current [[Constitution of France]], adopted by referendum on 4 October 1958, establishes the country as secular and democratic, with its sovereignty derived from the people. The nation\'s ideals are expressed in the foundational \'\'[[Declaration of the Rights of Man and of the Citizen]]\'\', one of the world\'s earliest documents on human rights, which was formulated during the seminal [[French Revolution]] of the late 18th century. France has been a major power in Europe since the [[Late Middle Ages]], reaching the height of its influence during the 19th and early 20th centuries, when it possessed the [[French colonial empire|second-largest colonial empire]] of the time, and one of the largest in history. This legacy is reflected in the prevalence of [[French language]], [[Culture of France|culture]], and [[Napoleonic Code|jurisprudence]] worldwide. France has produced many influential artists, thinkers, and scientists, and remains a prominent global centre of culture. It hosts the world\'s [[List of World Heritage Sites in France|fourth-largest]] number of cultural [[UNESCO World Heritage Sites]], drawing around 83 million foreign tourists annually – the most of any country in the world.&lt;ref name=&quot;tourism.stat&quot;&gt;{{cite web |publisher= United Nations World Tourism Organization |url=http://dtxtq4w60xqpw.cloudfront.net/sites/all/files/pdf/unwto_highlights13_en_lr.pdf |title=UNWTO Highlights |accessdate=11 September 2013|format=PDF}}{{dead link|date=January 2014}}&lt;/ref&gt; France remains a [[major power]] with signif'; preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0); // Print the entire match result var_dump($matches);

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