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
  • Match everything enclosed
    (?:...)
  • Capture everything enclosed
    (...)
  • 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

# coding=utf8 # the above tag defines encoding for this document and is for Python 2.x compatibility import re regex = r";\s*color:\s*#ff+;" test_str = ("<span id=\"JobDescCKEditor\" class=\"JobDescCKEditor\"><div class=\"sVx81\"style=\"color: #222222; font-size: 14px;\">\n" "<div class=\"OghIW\">\n" "<div class=\"sH3zFd\">\n" "<h2 class=\"KLsYvd\" style=\"font-size: 30px;\" tabindex=\"-1\">Dot Net Developer/Senior Developer/Lead</h2>\n" "<div class=\"MpVvlf sb-unsaved\">&nbsp;</div>\n" "<span class=\"SGdgT\"><span class=\"povykd\" tabindex=\"0\" role=\"button\" data-extra-container-classes=\"signin-content\" data-theme=\"0\" data-width=\"304\"><span class=\"pWJs7b sb-unsaved-label\" style=\"color: rgba(0, 0, 0, 0.54); font-size: 14px;\">SAVE</span></span></span>\n" "<div data-dst=\"Dot Net Developer/Senior Developer/Lead\" data-dsu=\";jobs&amp;q=asp.net+developer+jobs+in+coimbatore&amp;hl=en-IN&amp;kgs=fc48b0cab3c47379&amp;shndl=-1&amp;source=sh/x/im/textlists/detail&amp;entrypoint=sh/x/im/textlists/detail#fpstate=tldetail&amp;htivrt=jobs&amp;htiq=asp.net+developer+jobs+in+coimbatore&amp;htidocid=kt8uTf65bML56BEcAAAAAA%3D%3D\" data-shortu=\"\" data-jsdata=\"\" data-ved=\"0ahUKEwiC8vy606bsAhVl7HMBHfHOA9gQgmQI9gcwAA\">&nbsp;</div>\n" "</div>\n" "<div class=\"iGy6ud\">\n" "<div class=\"ZUeoqc\">\n" "<div style=\"font-size: 20px;\">\n" "<div class=\"EtwWxe\" style=\"color: #ffffff;\" aria-hidden=\"true\">I</div>\n" "</div>\n" "</div>\n" "<div class=\"tJ9zfc\" style=\"color: rgba(0, 0, 0, 0.54); font-size: 14px;\">\n" "<div class=\"nJlQNd sMzDkb\">Impiger Technologies</div>\n" "<div class=\"sMzDkb\">Coimbatore, Tamil Nadu</div>\n" "</div>\n" "</div>\n" "</div>\n" "</div>\n" "<div class=\"GfgB1\" style=\"color: #222222; font-size: 14px;\" data-ved=\"0ahUKEwiC8vy606bsAhVl7HMBHfHOA9gQn-cDCIEIMAA\">&nbsp;</div>\n" "<div class=\"mR2gOd\" data-hveid=\"1027\" data-ved=\"0ahUKEwiC8vy606bsAhVl7HMBHfHOA9gQ890CCIMIMAA\">\n" "<div class=\"EDblX DAVP1\">\n" "<div class=\"B8oxKe\"><span class=\"DaDV9e\" tabindex=\"-1\"><a class=\"\" style=\"color: #ffffff; font-size: 14px;\" title=\"Apply on AngelList\" target=\"_blank\" rel=\"noopener\" data-ved=\"0ahUKEwiC8vy606bsAhVl7HMBHfHOA9gQpowCCIQIKAAwAA\">Apply on AngelList</a></span></div>\n" "<div class=\"B8oxKe BQC79e\" data-jsdata=\"\">\n" "<div id=\"jdaokt8uTf65bML56BEcAAAAAA==\" class=\"y yf\" data-jiis=\"up\" data-async-type=\"jb_apply_options\" data-async-context-required=\"htidocid,ibp\" data-async-rclass=\"search\" data-ved=\"0ahUKEwiC8vy606bsAhVl7HMBHfHOA9gQld4CCIUIKAEwAA\"></div>\n" "</div>\n" "</div>\n" "</div>\n" "<div class=\"CyxPy EPhEaf\" style=\"color: #ffffff;\">&nbsp;</div>\n" "<div>&nbsp;</div>\n" "<div>&nbsp;</div>\n" "<div class=\"w5NUMb\" style=\"color: #222222; font-size: 14px;\">&nbsp;</div>\n" "<div class=\"ocResc icFQAc\" style=\"color: #222222; font-size: 14px;\"><span class=\"n1Mpqb\" style=\"color: rgba(0, 0, 0, 0.54);\"><span class=\"SuWscb\">Over 1 month ago</span></span><span class=\"n1Mpqb\" style=\"color: rgba(0, 0, 0, 0.54);\"><span class=\"SuWscb\">?2L–?9L a year</span></span><span class=\"n1Mpqb\" style=\"color: rgba(0, 0, 0, 0.54);\"><span class=\"SuWscb\">Full–time</span></span></div>\n" "<div class=\"YgLbBe\" style=\"color: rgba(0, 0, 0, 0.87); font-size: 14px;\">\n" "<div class=\"config-text-expandable\"><span class=\"HBvzbc\">· Demonstrate a high level of competence in object-oriented analysis, design, and coding in a .NET server-side environment, specifically in utilizing the Microsoft MVC framework. Experience in Angular is an added advantage. · Adhere to the standards and comply with HTML, CSS and JavaScript codes with respect to the artworks and technical specifications provided · Design and implement systems that use relational databases, specifically SQL 2008 R2 · Work on pre-defined requirements and produce code that meets the requirements · Demonstrate a structured approach to development, using design patterns wherever appropriate, and use SOLID principle and strive hard to continuously improve the development process · Take responsibility for the deliverables and contribute effectively to the team · Possess enthusiasm and passion for technology and crave for honing new skills Impiger Technologies focuses on Cloud Computing and Mobile Application. Their company has offices in Coimbatore<span class=\"WbZuDe\"> They have a large team that's between 201-500 employees. You can view their website at </span></span></div>\n" "</div>\n" "<div style=\"color: #222222; font-size: 14px;\" data-async-context=\"async_id:duf3-47-_K-R_X8KwOOXYz7sP8Z2PwA02;authority:0;card_id:;entry_point:0;feature_id:;ftoe:0;header:0;is_jobs_spam_form:1;open:0;preselect_answer_index:-1;suggestions:;suggestions_subtypes:;suggestions_types:;surface:0;title:;type:47\">\n" "<div id=\"duf3-47-_K-R_X8KwOOXYz7sP8Z2PwA02\" class=\"y yp\" data-jiis=\"up\" data-async-type=\"duffy3\" data-async-context-required=\"type,open,feature_id,async_id,entry_point,authority,card_id,ftoe,title,header,suggestions,surface,suggestions_types,suggestions_subtypes,preselect_answer_index,is_jobs_spam_form\" data-ved=\"0ahUKEwiC8vy606bsAhVl7HMBHfHOA9gQ-0EIjQgwAA\"></div>\n" "<div class=\"egHvEc hide-focus-ring\" tabindex=\"0\" role=\"link\" data-async-trigger=\"duf3-47-_K-R_X8KwOOXYz7sP8Z2PwA02\" data-ved=\"0ahUKEwiC8vy606bsAhVl7HMBHfHOA9gQ5ZkFCI4IMAA\"><span class=\"XVmsDd\" style=\"color: #212121; font-size: 14px;\">Report this listing</span></div>\n" "</div>\n" "<div class=\"gWhMmc\" style=\"color: #222222; font-size: 14px;\" data-jsdata=\"\">\n" "<div id=\"jdskt8uTf65bML56BEcAAAAAA==\" class=\"y yf\" data-jiis=\"up\" data-async-type=\"jb_salary\" data-async-context-required=\"htidocid,ibp\" data-async-rclass=\"search\" data-ved=\"0ahUKEwiC8vy606bsAhVl7HMBHfHOA9gQudsCCI8IMAA\">\n" "<div id=\"gws-plugins-horizon-jobs__salary\">\n" "<div class=\"iE9pwb\">\n" "<div class=\"XdTbkf\">\n" "<div class=\"bKLZtb BAgzfc\" style=\"color: rgba(0, 0, 0, 0.87);\">Salary comparison</div>\n" "<div class=\"URn80\">\n" "<div class=\"HWnzvc\" aria-label=\"More info\">&nbsp;</div>\n" "</div>\n" "</div>\n" "<div>\n" "<div class=\"ZDG8hb\" style=\"color: rgba(0, 0, 0, 0.54); font-size: 12px;\">\n" "<div class=\"UcFhic\">\n" "<div class=\"fjnW5b GPnHhd\">&nbsp;</div>\n" "Impiger Technologies</div>\n" "<div class=\"UcFhic\">\n" "<div class=\"ZZ1t4d GPnHhd\">&nbsp;</div>\n" "Local employers via&nbsp;<a class=\"aPBtBe\" style=\"color: #4285f4;\" target=\"_blank\" rel=\"noopener\">PayScale</a></div>\n" "</div>\n" "<div class=\"zrUdLc\">&nbsp;160k&nbsp;420k&nbsp;680k?2L–900k?2.2L–530k</div>\n" "</div>\n" "</div>\n" "</div>\n" "</div>\n" "</div>\n" "<div class=\"EWizoc\" style=\"color: #ffffff; font-size: 14px;\"><span class=\"sssrNe\" style=\"color: rgba(0, 0, 0, 0.87); font-size: 20px;\">Impiger Technologies</span></div>\n" "<div class=\"AtCEfb\" style=\"color: #222222; font-size: 14px;color: #ffffff;\" data-jsdata=\"\">\n" "<div id=\"fc_6\" class=\"y yf\" data-async-fc=\"EvcBCrcBQUc4Q2tLaDZqNk45dEZldmx6OFhzWlE1SzJzZ2pZckNuOW1RTVRFb3JIbjVpY0swalFGM3lJYjNxU2h2d1ZvMXNRSXl0WHhSWDF4S3h5bzBGV2VXTEpxS2lIdTdqN1RoTHVuN0ZYTnVHdGJ4eHBjdnVVVkFpYXdjMlNDdGMzSUxwOW83Q3FxRERjeERNbm8wX2tKMnY4cmpnc2o4bE82Y0pjckIwMkpQVXBtVTBVNVVhTzJ2VGRjEhdLLVJfWDhLd09PWFl6N3NQOFoyUHdBMBoiQU1lZHd5TEk0dkd2LUVaTjdHQ2VPblJVbkM4cWpob0d6QQ\" data-async-fcv=\"3\" data-async-ons=\"731\" data-async-rclass=\"search\" data-ved=\"0ahUKEwiC8vy606bsAhVl7HMBHfHOA9gQmbECCJAIMAA\">\n" "<div>\n" "<div class=\"gaLgbc\">\n" "<div class=\"qySoyb\" style=\"color: rgba(0, 0, 0, 0.87); font-size: 14px;background-color: #ffffff\">Glassdoor</div>\n" "</div>\n" "</div>\n" "</div>\n" "</div></span>") subst = ";" # You can manually specify the number of replacements by changing the 4th argument result = re.sub(regex, subst, test_str, 0, re.MULTILINE) if result: print (result) # Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.

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 Python, please visit: https://docs.python.org/3/library/re.html