Regular Expressions 101

Save & Share

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
No Match

/
/
gm

Test String

Substitution

Processing...

Code Generator

Generated Code

const regex = /(url\\?":\\?")(?!http|https)(.*?)"/gm; // Alternative syntax using RegExp constructor // const regex = new RegExp('(url\\\\?":\\\\?")(?!http|https)(.*?)"', 'gm') const str = `"{"blocks":[{"key":"dimrp","text":"bratwurst currywurst ","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[{"offset":0,"length":9,"key":0},{"offset":10,"length":10,"key":1}],"data":{}}],"entityMap":{"0":{"type":"LINK","mutability":"MUTABLE","data":{"url":"http://www.google.com","targetOption":"_blank"}},"1":{"type":"LINK","mutability":"MUTABLE","data":{"url":"www.berlin.de","targetOption":"_blank"}}, "2":{"type":"LINK","mutability":"MUTABLE","data":{"url":"javascript:alert(101)","targetOption":"_blank"}}, "3":{"type":"LINK","mutability":"MUTABLE","data":{"url":"https//www.google.com","targetOption":"_blank"}}}}" {"header":{"account_id":"b05f9df8-cd3b-4b30-b57b-5b45ffaac62f","aggregate_id":"9e168575-4127-4c69-beaf-f117dbab87e8","aggregate_name":"GUIDES","aggregate_root_id":"9e168575-4127-4c69-beaf-f117dbab87e8","aggregate_version":32,"correlation_id":"d89b000e-9b9c-4799-881a-ea4547f922d3","msg_id":"0955de48-8488-4989-a86f-e19c8bbf739a","msg_key":"9e168575-4127-4c69-beaf-f117dbab87e8","msg_schema_name":"EDIT_TEXT_IN_TEXT_WIDGET","msg_schema_version":1,"msg_timestamp":1557938204180,"msg_topic":"MICHAEL.TOPIC_COMMANDS","source_system_instance_id":"240b62d7-7e6e-4c4a-8f5c-1c816b16012c","source_system_name":"BynderAPI_V2__development__node_http_service_skel__0.0.1__240b62d7-7e6e-4c4a-8f5c-1c816b16012c","user_id":"ab851f80-916b-4e12-a49c-b70e6ab1f817"},"payload":{"chapter_id":"cc1403b7-302a-4d0d-8a95-96b99a20c306","page_id":"965f6828-6878-4795-81b6-066c207b2ca9","section_id":"3e223fc9-78d6-4a60-9d27-2224d7cd4a35","widget_id":"e976646e-0bed-4c12-9893-9688d6c89dbe","widget_type":"text","widget_text":"{\\"blocks\\":[{\\"key\\":\\"bg6c2\\",\\"text\\":\\"Helllo World \\",\\"type\\":\\"unstyled\\",\\"depth\\":0,\\"inlineStyleRanges\\":[],\\"entityRanges\\":[{\\"offset\\":0,\\"length\\":6,\\"key\\":0},{\\"offset\\":8,\\"length\\":5,\\"key\\":1}],\\"data\\":{}}],\\"entityMap\\":{\\"0\\":{\\"type\\":\\"LINK\\",\\"mutability\\":\\"MUTABLE\\",\\"data\\":{\\"url\\":\\"https://www.bynder.com\\",\\"targetOption\\":\\"_blank\\"}},\\"1\\":{\\"type\\":\\"LINK\\",\\"mutability\\":\\"MUTABLE\\",\\"data\\":{\\"url\\":\\"www.google.com\\",\\"targetOption\\":\\"_blank\\"}}}}","command_time":"2019-05-15T16:36:44.166Z","guide_id":"9e168575-4127-4c69-beaf-f117dbab87e8","guide_version":32}} `; const subst = `$1https://$2"`; // The substituted value will be contained in the result variable const result = str.replace(regex, subst); console.log('Substitution result: ', result);

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 JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions