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

/
/
gm

Test String

Code Generator

Generated Code

use strict; my $str = '#걸려야함 4nYoywMzx6630636\\x010\\x0200\\x011\\x011\\x03\\x14\\x03\\x14\\x03\\x03\\x0820210430\\x0820410430\\x0820210430\\x0820410430\\x03(\\x071000000(\\x041190\\x03.\\x0202(\\x010\\x03d\\x08207504306AAAU(\\x0230\\x1e012020460104600200000000020020\\x1e01202046010460020000000002002030630636009910200201020020000999--020020------2-01--\\x03CTL\\x013(\\x010(\\x010(\\x010(\\x010(\\x010(\\x010(\\x010\\x03#NA(\\x011(\\x010(\\x010(\\x010\\x011\\x03(\\x011\\x03-\\x01 \\x03#NA\\x011\\x01 \\x011\\x0200(\\x041190(\\x010\\x03N갱신형 재진단암진단비(2년 대기형)[기본계약](계속보장형)\\x03\\x01 \\x012\\x03#NA\\x03\\x03#NA(\\x041190\\x03#NA(\\x010\\x012\\x03#NA\\x03#NA\\x010(\\x010(\\x010(\\x010(\\x010(\\x010(\\x010\\x03(\\x010\\x03\\x03\\x03\\x03(\\x010\\x0220\\x01 \\x01 (\\x010\\x03\\x01{\\x03\\x03\\x03\\n 4nYpMQSq0v620255\\x010\\x0200\\x011\\x011\\x03\\x01\\x03\\x01\\x03\\x03\\x0820210430\\x0820220430\\x0820210430\\x0820220430\\x03(\\x0850000000(\\x041320\\x03*\\x0201(\\x0215\\x03\\x08203604306AABI(\\x011\\x1c0100104223310010000000001001\\x1c0100104223310010000000001001/0620255009990009999000999000999----------2-01--\\x03CTL\\x013(\\x010\\x011(\\x010(\\x010(\\x010(\\x010(\\x010(\\x010\\x03#NA(\\x011(\\x010(\\x010(\\x010\\x011\\x03(\\x011\\x03)\\x01 \\x03#NA\\x011\\x01 \\x011\\x0200(\\x041811(\\x010\\x03\\x1f갱신형 상해입원의료비\\x03\\x03100\\x011\\x03#NA\\x03\\x03#NA(\\x041320\\x013(\\x010\\x012\\x03#NA\\x03#NA\\x011(\\x010(\\x010(\\x010(\\x010(\\x010(\\x010\\x03(\\x010\\x03\\x03\\x03\\x03(\\x010\\x0201\\x01 \\x01 (\\x010\\x03_\\x01{\\x03\\x03\\x02\\n \\(\\\\x08([0-9]{4,})\\([0-9]{3,} \'4nXfg3E6Qb(\\x011(\\x011\\x03CTL\\x133190026942021031120\\x0201\\x040001\\n\' '; my $regex = qr/\(\\x07([0-9]{4,})|\(\\t([0-9]{4,})\(/mp; if ( $str =~ /$regex/g ) { print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n"; # print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n"; # print "Capture Group 2 is $2 ... and so on\n"; } # ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p' # Named capture groups can be called via $+{name}

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 Perl, please visit: http://perldoc.perl.org/perlre.html