Regular Expressions 101

Save & Share

  • Regex Version: ver. 1
  • 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

/
/

Test String

Code Generator

Generated Code

// include the latest version of the regex crate in your Cargo.toml extern crate regex; use regex::Regex; fn main() { let regex = Regex::new(r#"\{\s*ADDIN ZOTERO_ITEM.*http\:\/\/zotero\.org\/.*items\/([^\"]*).*\}\s*}"#).unwrap(); let string = "The current wave of protests formed through the coming together of three elements. <i>First</i>, some students demonstrated on various university campuses (mainly Táchira) for at least two weeks before the big 12 February 2014 protests. They protested against <i>insecurity</i> and Venezuela’s high crime rates. Vivia Sequera from the Christian Science Monitor claims that students at the University of the Andes were initially protesting an attempted rape of a young woman on campus.<a title=\"\" href=\"#_ftn1\">[1]</a> &nbsp; some opposition leaders mobilised their supporters and the Venezuelan Student Movement to protest against the government and call for its resignation – prominently <i>Leopoldo López</i>, leader of the centrist party Voluntad Popular (VP, Popular Will), <i>María Corina Machado</i> of the liberal party Vente Venezuela (Come Venezuela) and <i>Antonio Ledezma</i> of the social democratic party Alianza Bravo Pueblo (Fearless People's Alliance).<a title=\"\" href=\"#_ftn2\">[2]</a> It is sig <div><br clear=\"all\" /> <hr align=\"left\" size=\"1\" width=\"33%\" /> <div> <a title=\"\" href=\"#_ftnref1\">[1]</a> { ADDIN ZOTERO_ITEM CSL_CITATION {\"citationID\":\"klJTkj1B\",\"properties\":{\"formattedCitation\":\"{\\\\rtf Vivia Sequera, \\\\uc0\\\\u8220{}Did Attempted Rape Ignite Venezuela\\\\uc0\\\\u8217{}s National Protests?,\\\\uc0\\\\u8221{} \\\\i Christian Science Monitor\\\\i0{}, February 22, 2014, http://www.csmonitor.com/World/Latest-News-Wires/2014/0222/Did-attempted-rape-ignite-Venezuela-s-national-protests.}\",\"plainCitation\":\"Vivia Sequera, “Did Attempted Rape Ignite Venezuela’s National Protests?,” Christian Science Monitor, February 22, 2014, http://www.csmonitor.com/World/Latest-News-Wires/2014/0222/Did-attempted-rape-ignite-Venezuela-s-national-protests.\"},\"citationItems\":[{\"id\":1080,\"uris\":[\"http://zotero.org/groups/228165/items/U8EBSIQM\"],\"uri\":[\"http://zotero.org/groups/228165/items/U8EBSIQM\"],\"itemData\":{\"id\":1080,\"type\":\"article-magazine\",\"title\":\"Did attempted rape ignite Venezuela's national protests?\",\"container-title\":\"Christian Science Monitor\",\"source\":\"Christian Science Monitor\",\"abstract\":\"Student protests began at the University of the Andes in San Cristobal, Venezuela, after an attempted rape of a college woman. A week later, the protests boiled over into a violent national uprising.\",\"URL\":\"http://www.csmonitor.com/World/Latest-News-Wires/2014/0222/Did-attempted-rape-ignite-Venezuela-s-national-protests\",\"ISSN\":\"0882-7729\",\"author\":[{\"family\":\"Sequera\",\"given\":\"Vivia\"}],\"issued\":{\"date-parts\":[[\"2014\",2,22]]},\"accessed\":{\"date-parts\":[[\"2014\",4,7]]}}}],\"schema\":\"https://github.com/citation-style-language/schema/raw/master/csl-citation.json\"} } </div> <div> <a title=\"\" href=\"#_ftnref2\">[2]</a> { ADDIN ZOTERO_ITEM CSL_CITATION {\"citationID\":\"4YnaAzSw\",\"properties\":{\"formattedCitation\":\"{\\\\rtf Sara Carolina D\\\\uc0\\\\u237{}az, \\\\uc0\\\\u8220{}Sector de La Oposici\\\\uc0\\\\u243{}n Convoca a Marcha Para El 12 de Febrero,\\\\uc0\\\\u8221{} February 2, 2014, http://www.eluniversal.com/nacional-y-politica/140202/sector-de-la-oposicion-convoca-a-marcha-para-el-12-de-febrero.}\",\"plainCitation\":\"Sara Carolina Díaz, “Sector de La Oposición Convoca a Marcha Para El 12 de Febrero,” February 2, 2014, http://www.eluniversal.com/nacional-y-politica/140202/sector-de-la-oposicion-convoca-a-marcha-para-el-12-de-febrero.\"},\"citationItems\":[{\"id\":1136,\"uris\":[\"http://zotero.org/groups/228165/items/MTSN6T7J\"],\"uri\":[\"http://zotero.org/groups/228165/items/MTSN6T7J\"],\"itemData\":{\"id\":1136,\"type\":\"post-weblog\",\"title\":\"Sector de la oposición convoca a marcha para el 12 de febrero\",\"abstract\":\"Caracas.- Cientos de personas atendieron el llamado de parte de la dirigencia opositora y de Voluntad Popular en la plaza Brión de Chacaíto para participar en una asamblea popular con el fin de expresar su opinión sobre la salida posible a la crisis (...)\",\"URL\":\"http://www.eluniversal.com/nacional-y-politica/140202/sector-de-la-oposicion-convoca-a-marcha-para-el-12-de-febrero\",\"author\":[{\"family\":\"Díaz\",\"given\":\"Sara Carolina\"}],\"issued\":{\"date-parts\":[[\"2014\",2,2]]},\"accessed\":{\"date-parts\":[[\"2014\",4,7]]}}}],\"schema\":\"https://github.com/citation-style-language/schema/raw/master/csl-citation.json\"} } </div> </div>"; // result will be a tuple containing the start and end indices for the first match in the string let result = regex.captures(string); let (start, end) = match result { Some((s, e)) => (s, e), None => { // ... } }; println!("{}", &string[start, end]); }

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 Rust, please visit: https://docs.rs/regex/latest/regex/