Regular Expressions 101

Save & Manage Regex

  • Current Version: 1
  • Save & Share
  • Community Library

Flavor

  • PCRE2 (PHP)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java
  • .NET 7.0 (C#)
  • Rust
  • PCRE (Legacy)
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests
Sponsors
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
Processing...

Test String

Substitution
Processing...

Code Generator

Generated Code

import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main(String[] args) { final String regex = "(\\*\\h*\\[(?:x| )\\])\\h*(\\w*)"; final String string = "* [x] homepage_url\n" + "* [x] description_good\n" + "* [x] interact\n" + "* [x] contribution\n" + "* [x] contribution_requirements\n" + "* [x] floss_license\n" + "* [x] floss_license_osi\n" + "* [x] license_location\n" + "* [x] documentation_basics\n" + "* [x] documentation_interface\n" + "* [x] sites_https\n" + "* [x] discussion\n" + "* [x] english\n" + "* [x] repo_public\n" + "* [x] repo_track\n" + "* [x] repo_interim\n" + "* [x] repo_distributed\n" + "* [x] version_unique\n" + "* [x] version_semver\n" + "* [x] version_tags\n" + "* [x] release_notes\n" + "* [ ] release_notes_vulns (@marmarek: Are QSBs always mentioned in release notes?)\n" + "* [x] report_process\n" + "* [x] report_tracker\n" + "* [x] report_responses\n" + "* [x] enhancement_responses\n" + "* [x] report_archive\n" + "* [x] vulnerability_report_process\n" + "* [x] vulnerability_report_private\n" + "* [x] build\n" + "* [ ] build_common_tools (@marmarek: Does `qubes-builder` use \"common tools\"?)\n" + "* [x] build_floss_tools\n" + "* [x] test\n" + "* [ ] test_invocation (@marmarek: Please fill in all \"test\" and \"warning\" criteria met.)\n" + "* [ ] test_most\n" + "* [ ] test_continuous_integration\n" + "* [ ] test_policy\n" + "* [ ] tests_are_added\n" + "* [ ] tests_documented_added\n" + "* [ ] warnings\n" + "* [ ] warnings_fixed\n" + "* [ ] warnings_strict\n" + "* [x] know_secure_design\n" + "* [x] know_common_errors\n" + "* [x] crypto_published\n" + "* [x] crypto_call\n" + "* [x] crypto_floss\n" + "* [x] crypto_keylength\n" + "* [x] crypto_working\n" + "* [x] crypto_weaknesses (arguably `qvm-backup` still passes despite #971)\n" + "* [x] crypto_pfs\n" + "* [x] crypto_password_storage\n" + "* [x] crypto_random\n" + "* [x] delivery_mitm\n" + "* [x] delivery_unsigned\n" + "* [x] vulnerabilities_fixed_60_days\n" + "* [x] vulnerabilities_critical_fixed\n" + "* [x] no_leaked_credentials\n" + "* [ ] static_analysis (@marmarek: Please fill in all \"analysis\" criteria met.)\n" + "* [ ] static_analysis_common_vulnerabilities\n" + "* [ ] static_analysis_fixed\n" + "* [ ] static_analysis_often\n" + "* [ ] dynamic_analysis\n" + "* [ ] dynamic_analysis_enable_assertions\n" + "* [ ] dynamic_analysis_fixed\n\n" + "Future Criteria\n" + "-------------\n\n" + "* [x] installation_common (depends on how this applies to OSes)\n" + "* [ ] build_reproducible\n" + "* [x] crypto_used_network\n" + "* [x] crypto_tls12\n" + "* [x] crypto_certificate_verification\n" + "* [x] crypto_verification_private\n" + "* [ ] hardened_site\n" + "* [ ] hardening\n"; final String subst = "\\1 [\\2](https://github.com/linuxfoundation/cii-best-practices-badge/blob/master/doc/criteria.md#\\2)"; final Pattern pattern = Pattern.compile(regex); final Matcher matcher = pattern.matcher(string); // The substituted value will be contained in the result variable final String result = matcher.replaceAll(subst); System.out.println("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 Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html