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 single character of: a, b, c or d
    [[ab][cd]]
  • 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]
  • Character class intersection
    [\w&&[^\d]]
  • 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

import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main(String[] args) { final String regex = "(?m)^(\\h*)maxlength:(?:\\R\\1(?!\\h*maxlength_js_enforce:)(\\h+).*)*$(?!\\R\\1\\h)"; final String string = "uuid: e3737897-ae40-4771-8aff-33d2fe76eeee\n" + "langcode: de\n" + "status: true\n" + "dependencies:\n" + " config:\n" + " - config_pages.type.chatbot\n" + " - field.field.config_pages.chatbot.field_2click_solution_label\n" + " - field.field.config_pages.chatbot.field_2click_solution_logo\n" + " - field.field.config_pages.chatbot.field_2click_solution_popup_text\n" + " - field.field.config_pages.chatbot.field_title_div\n" + " - field.field.config_pages.chatbot.field_url\n" + " module:\n" + " - field_group\n" + " - field_states_ui\n" + " - file\n" + " - link\n" + " - link_field_tweak\n" + " - maxlength\n" + " - text\n" + "third_party_settings:\n" + " field_group:\n" + " group_struktur_definitionen:\n" + " children:\n" + " - group_tab_settings\n" + " - group__tab_policy\n" + " label: 'Chatbot Einstellungen'\n" + " region: content\n" + " parent_name: ''\n" + " weight: 1\n" + " format_type: tabs\n" + " format_settings:\n" + " classes: ''\n" + " show_empty_fields: false\n" + " id: ''\n" + " direction: horizontal\n" + " width_breakpoint: 640\n" + " group_tab_settings:\n" + " children:\n" + " - field_url\n" + " - field_2click_solution_logo\n" + " - field_title_div\n" + " label: Einstellungen\n" + " region: content\n" + " parent_name: group_struktur_definitionen\n" + " weight: 20\n" + " format_type: tab\n" + " format_settings:\n" + " classes: ''\n" + " show_empty_fields: false\n" + " id: ''\n" + " formatter: closed\n" + " description: ''\n" + " required_fields: true\n" + " group__tab_policy:\n" + " children:\n" + " - field_2click_solution_label\n" + " - field_2click_solution_popup_text\n" + " label: Datenschutzhinweis\n" + " region: content\n" + " parent_name: group_struktur_definitionen\n" + " weight: 21\n" + " format_type: tab\n" + " format_settings:\n" + " classes: ''\n" + " show_empty_fields: false\n" + " id: ''\n" + " formatter: closed\n" + " description: ''\n" + " required_fields: true\n" + "id: config_pages.chatbot.default\n" + "targetEntityType: config_pages\n" + "bundle: chatbot\n" + "mode: default\n" + "content:\n" + " field_2click_solution_label:\n" + " type: string_textfield\n" + " weight: 22\n" + " region: content\n" + " settings:\n" + " size: 60\n" + " placeholder: ''\n" + " third_party_settings:\n" + " field_states_ui:\n" + " form:\n" + " type: ''\n" + " list: ''\n" + " add: Hinzufügen\n" + " maxlength:\n" + " maxlength_js: 60\n" + " maxlength_js_label: 'Inhalt auf @limit Zeichen begrenzt, verbleibend: <strong>@remaining</strong><br><br>'\n" + " field_2click_solution_logo:\n" + " type: file_generic\n" + " weight: 22\n" + " region: content\n" + " settings:\n" + " progress_indicator: throbber\n" + " third_party_settings: { }\n" + " field_2click_solution_popup_text:\n" + " type: text_textarea\n" + " weight: 23\n" + " region: content\n" + " settings:\n" + " rows: 5\n" + " placeholder: ''\n" + " third_party_settings:\n" + " field_states_ui:\n" + " form:\n" + " type: ''\n" + " list: ''\n" + " maxlength:\n" + " maxlength_js: null\n" + " maxlength_js_label: 'Inhalt auf @limit Zeichen begrenzt, verbleibend: <strong>@remaining</strong>'\n" + " maxlength_js_enforce: true\n" + " maxlength_js_truncate_html: false\n" + " field_title_div:\n" + " type: string_textfield\n" + " weight: 23\n" + " region: content\n" + " settings:\n" + " size: 60\n" + " placeholder: ''\n" + " third_party_settings: { }\n" + " field_url:\n" + " type: link_default\n" + " weight: 21\n" + " region: content\n" + " settings:\n" + " placeholder_url: 'URL zu einer JavaScript Datei'\n" + " placeholder_title: ''\n" + " third_party_settings:\n" + " field_states_ui:\n" + " form:\n" + " type: ''\n" + " list: ''\n" + " add: Hinzufügen\n" + " link_field_tweak:\n" + " uri_part_custom_help: false\n" + " uri_part_custom_help_text: ''\n" + " maxlength:\n" + " maxlength_js: null\n" + " maxlength_js_label: 'Inhalt auf @limit Zeichen begrenzt, verbleibend: <strong>@remaining</strong>'\n" + "hidden:\n" + " label: true\n" + " path: true\n"; final String subst = "$0\\n$1$2maxlength_js_enforce: true"; final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE); 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