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

r"
"
gs

Test String

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 = " SG_ (\\w+) : (\\d+)\\|(\\d+)@[01][+-] \\(([0-9E\\-\\+\\.]*),([0-9E\\-\\+\\.]*)\\) \\[[0-9E\\-\\+\\.]*\\|[0-9E\\-\\+\\.]*\\] \"([^\"]*)\" Vector__XXX"; final String string = "VERSION \"\"\n\n\n" + "NS_ : \n" + " NS_DESC_\n" + " CM_\n" + " BA_DEF_\n" + " BA_\n" + " VAL_\n" + " CAT_DEF_\n" + " CAT_\n" + " FILTER\n" + " BA_DEF_DEF_\n" + " EV_DATA_\n" + " ENVVAR_DATA_\n" + " SGTYPE_\n" + " SGTYPE_VAL_\n" + " BA_DEF_SGTYPE_\n" + " BA_SGTYPE_\n" + " SIG_TYPE_REF_\n" + " VAL_TABLE_\n" + " SIG_GROUP_\n" + " SIG_VALTYPE_\n" + " SIGTYPE_VALTYPE_\n" + " BO_TX_BU_\n" + " BA_DEF_REL_\n" + " BA_REL_\n" + " BA_DEF_DEF_REL_\n" + " BU_SG_REL_\n" + " BU_EV_REL_\n" + " BU_BO_REL_\n\n" + "BS_:\n\n" + "BU_:\n\n\n" + "BO_ 777 VBOX_9: 8 Vector__XXX\n" + " SG_ Longitude_48bit : 7|48@0- (1E-07,0) [0|0] \"minutes\" Vector__XXX\n\n" + "BO_ 776 VBOX_8: 8 Vector__XXX\n" + " SG_ Latitude_48bit : 7|48@0- (1E-07,0) [0|0] \"minutes\" Vector__XXX\n" + " SG_ Kalman_filter_status : 56|1@0+ (1,0) [0|1] \"\" Vector__XXX\n\n" + "BO_ 774 VBOX_6: 8 Vector__XXX\n" + " SG_ Vel_Quality : 7|16@0- (0.01,0) [0|0] \"km/h\" Vector__XXX\n\n" + "BO_ 773 VBOX_5: 8 Vector__XXX\n" + " SG_ Trig_Vel_Mph : 55|16@0+ (0.0115078,0) [0|754.163673] \"Mph\" Vector__XXX\n" + " SG_ Trig_Vel_Kmh : 55|16@0+ (0.01852,0) [0|1213.7082] \"Km/h\" Vector__XXX\n" + " SG_ Trig_time : 39|16@0+ (0.01,0) [0|655.35] \"Secs\" Vector__XXX\n" + " SG_ Distance : 7|32@0+ (7.8125E-05,0) [0|335544] \"Metres\" Vector__XXX\n\n" + "BO_ 772 VBOX_4: 8 Vector__XXX\n" + " SG_ Lateral_acceleration : 55|16@0- (0.01,0) [-327.68|327.67] \"G\" Vector__XXX\n" + " SG_ Longitudinal_acceleration : 39|16@0- (0.01,0) [-327.68|327.67] \"G\" Vector__XXX\n" + " SG_ Trig_Dist : 7|32@0+ (7.8125E-05,0) [0|335544] \"Metres\" Vector__XXX\n\n" + "BO_ 771 VBOX_3: 8 Vector__XXX\n" + " SG_ DGPS : 61|1@0+ (1,0) [0|0] \"On\" Vector__XXX\n" + " SG_ Brake_trigger : 60|1@0+ (1,0) [0|0] \"On\" Vector__XXX\n" + " SG_ Vertical_Velocity : 31|16@0- (0.01,0) [0|655.36] \"m/s\" Vector__XXX\n" + " SG_ Altitude_WGS84 : 7|24@0- (0.01,0) [0|42949700] \"metres\" Vector__XXX\n\n" + "BO_ 770 VBOX_2: 8 Vector__XXX\n" + " SG_ Velocity_Mph : 39|16@0+ (0.0115078,0) [0|754.163673] \"Mph\" Vector__XXX\n" + " SG_ Heading : 55|16@0+ (0.01,0) [0|359.99] \"Degrees\" Vector__XXX\n" + " SG_ Velocity_Kmh : 39|16@0+ (0.01852,0) [0|1213.7082] \"Km/h\" Vector__XXX\n" + " SG_ Longitude : 7|32@0- (1E-05,0) [-21474.83648|21474.83647] \"Minutes\" Vector__XXX\n\n" + "BO_ 769 VBOX_1: 8 Vector__XXX\n" + " SG_ Latitude : 39|32@0- (1E-05,0) [-21474.83648|21474.83647] \"Minutes\" Vector__XXX\n" + " SG_ Time_Since_Midnight : 15|24@0+ (0.01,0) [0|0] \"Seconds\" Vector__XXX\n" + " SG_ Sats : 7|8@0+ (1,0) [0|12] \"Sats\" Vector__XXX\n"; final Pattern pattern = Pattern.compile(regex, Pattern.DOTALL); final Matcher matcher = pattern.matcher(string); while (matcher.find()) { System.out.println("Full match: " + matcher.group(0)); for (int i = 1; i <= matcher.groupCount(); i++) { System.out.println("Group " + i + ": " + matcher.group(i)); } } } }

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