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

import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main(String[] args) { final String regex = "(?#Header Cielo 03)^0([\\d]{10})([\\d]{8})([\\d]{8})([\\d]{8})([\\d]{7})([CIELO]{5})([03]{2})([I|P]{1})([\\w\\s]{20})([001]{3})([\\w\\s]{177})$|(?#RO Venda Cielo 03)^1([\\d]{10})([\\d]{7})([\\d\\s]{2})([a,\\/,\\s]{1})([\\d\\s]{2})(01)([\\d]{6})([\\d]{6})([\\d]{6})([\\D\\d]{14})([\\D\\d]{14})([\\D\\d]{14})([\\D\\d]{14})([\\d]{4})([\\d]{5})([\\d\\s]{14})(00)([\\d]{6})([\\d]{2})([\\d]{6})([\\sRA]{1})([\\d]{6})([\\s]{2})([\\d]{13})([\\sCA]{1})([\\d\\S]{9})([\\D\\d]{14})([\\d]{3})([\\d]{22})([\\d]{4})([\\d]{5})([\\d]{4})([\\d\\w\\s]{2})([\\w\\s]{8})([\\d]{3})([\\s]{15})$|(?#CV Cielo 03)^2([\\d]{10})([\\d]{7})([\\d\\D]{19})([\\d]{8})([\\D\\d]{14})([\\d]{2})([\\d]{2})([\\w\\s]{3})([\\w\\s]{6})([\\d\\s]{20})([\\d]{6})([\\d]{13})([\\d]{2})([\\d]{13})([\\d\\s]{13})([\\d]{9})([0-2]{4})([\\w\\s]{8})([\\s|TX|VE]{2})([\\d\\s]{20})([\\d]{6})([\\d]{29})([\\w\\s]{1})([\\s]{32})$|(?#RO Pago Cielo 03)^1([\\d]{10})([\\d]{7})([\\d\\s]{2})([a,\\/,\\s]{1})([\\d\\s]{2})(01)([\\d]{6})([\\d]{6})([\\d]{6})([\\D\\d]{14})([\\D\\d]{14})([\\D\\d]{14})([\\D\\d]{14})([\\d]{4})([\\d]{5})([\\d\\s]{14})(01)([\\d]{6})([\\d]{2})([\\d]{6})([\\sRA]{1})([\\d]{6})([\\s\\d]{2})([\\d]{13})([\\sCA]{1})([\\d\\S]{9})([\\D\\d]{14})([\\d]{3})([\\d]{22})([\\d]{4})([\\d]{5})([\\d]{4})([\\d\\w\\s]{2})([\\w\\s]{8})([\\d]{3})([\\s]{15})$|(?#RO Serviço Cielo 03 Ajuste e Serviços)^1([\\d]{10})([\\d]{7})([\\d\\s]{2})([a,\\/,\\s]{1})([\\d\\s]{2})(02|03|04|05)([\\d]{6})([\\d]{6})([\\d]{6})([\\D\\d]{14})([\\D\\d]{14})([\\D\\d]{14})([\\D\\d]{14})([\\d]{4})([\\d]{5})([\\d\\s]{14})(00|01|02|03)([\\d]{6})([\\d]{2})([\\d]{6})([\\sRA]{1})([\\d]{6})([\\s\\d]{2})([\\d]{13})([\\sCA]{1})([\\d\\S]{9})([\\D\\d]{14})([\\d]{3})([\\d]{22})([\\d]{4})([\\d]{5})([\\d]{4})([\\d\\w\\s]{2})([\\w\\s]{8})([\\d]{3})([\\s]{15})$|(?#RO Enviado Banco Cielo 03)^1([\\d]{10})([\\d]{7})([\\d\\s]{2})([a,\\/,\\s]{1})([\\d\\s]{2})(01)([\\d]{6})([\\d]{6})([\\d]{6})([\\D\\d]{14})([\\D\\d]{14})([\\D\\d]{14})([\\D\\d]{14})([\\d]{4})([\\d]{5})([\\d\\s]{14})(02)([\\d]{6})([\\d]{2})([\\d]{6})([\\sRA]{1})([\\d]{6})([\\s\\d]{2})([\\d]{13})([\\sCA]{1})([\\d\\S]{9})([\\D\\d]{14})([\\d]{3})([\\d]{22})([\\d]{4})([\\d]{5})([\\d]{4})([\\d\\w\\s]{2})([\\w\\s]{8})([\\d]{3})([\\s]{15})$|(?#RO A CONFIRMAR Cielo 03)^1([\\d]{10})([\\d]{7})([\\d\\s]{2})([a,\\/,\\s]{1})([\\d\\s]{2})(01)([\\d]{6})([\\d]{6})([\\d]{6})([\\D\\d]{14})([\\D\\d]{14})([\\D\\d]{14})([\\D\\d]{14})([\\d]{4})([\\d]{5})([\\d\\s]{14})(03)([\\d]{6})([\\d]{2})([\\d]{6})([\\sRA]{1})([\\d]{6})([\\s\\d]{2})([\\d]{13})([\\sCA]{1})([\\d\\S]{9})([\\D\\d]{14})([\\d]{3})([\\d]{22})([\\d]{4})([\\d]{5})([\\d]{4})([\\d\\w\\s]{2})([\\w\\s]{8})([\\d]{3})([\\s]{15})$|(?#Trailer Cielo 03)^9\\d{11}.*$"; final String string = "010072994502016122720161227201612270006712CIELO03PEC2354 001 \n" + "110072994505161226 01161226170125000000+0000000004525-0000000000226+0000000000000+0000000004299023700974000002239P 0000000146000000 161226 0000000000000 000000000+0000000000000007163610370009502000000005000000000000242183323046 \n" + "210072994505161226506700******601300020161226+00000000045250000 852956 26011900000000000001600000000000000000000000000000000000000142183323 18285816361037000950200000000001000 \n" + "110072994505161226 01161226161227000000+0000000002000-0000000000036+0000000000000+0000000001964010400461000030090036750000000171000000 161226 0000000000000 000000000+00000000000000071636160900195540000000018200000000001WR023012071 \n" + "210072994505161226627780******473200020161226+00000000020000000 721689 777266000000000000016000000000000000000000000000000000000001WR023012 18223616361609001955400000000001000 \n" + "110072994505161226 01161226161227000000+0000000013218-0000000000240+0000000000000+0000000012978010400461000030090036750000000571000000 161226 0000000000000 000000000+0000000000000007163615060072658000000001820000000000242183323071 \n" + "210072994505161226627780******573300020161226+00000000021700000 114576 26000400000000000001600000000000000000000000000000000000000142183323 08263816361506007265800000000001000 \n" + "210072994505161226627780******074400020161226+00000000016520000 203138 26002100000000000001600000000000000000000000000000000000000142183323 09552916361506007265800000000002000 \n" + "210072994505161226627780******016500020161226+00000000034370000 475524 26003500000000000001600000000000000000000000000000000000000142183323 11051216361506007265800000000003000 \n" + "210072994505161226627780******978100020161226+00000000024240000 494289 26003600000000000001600000000000000000000000000000000000000142183323 11060716361506007265800000000004000 \n" + "210072994505161226627780******521100020161226+00000000035350000 242001 26004900000000000001600000000000000000000000000000000000000142183323 11411916361506007265800000000005000 \n" + "110072994505161226 01161226161227000000+0000000001515-0000000000028+0000000000000+0000000001487010400461000030090036750000000171000000 161226 0000000000000 000000000+0000000000000007163615070073805000000001820000000000242183323071 \n" + "210072994505161226506731******910600020161226+00000000015150000 383179 26006200000000000001600000000000000000000000000000000000000142183323 14325916361507007380500000000001000 \n" + "110072994505161226 01161226161227000000+0000000023435-0000000000426+0000000000000+0000000023009010400461000030090036750000000971000000 161226 0000000000000 000000000+0000000000000007163615080063547000000001820000000000242183323071 \n" + "210072994505161226627780******713600020161226+00000000019840000 529099 26007300000000000001600000000000000000000000000000000000000142183323 15302716361508006354700000000001000 \n" + "210072994505161226627780******259900020161226+00000000012900000 761140 26008900000000000001600000000000000000000000000000000000000142183323 17281616361508006354700000000002000 \n" + "210072994505161226627780******573300020161226+00000000036000000 170156 26009700000000000001600000000000000000000000000000000000000142183323 17502116361508006354700000000003000 \n" + "210072994505161226506731******320100020161226+00000000044090000 385284 26010400000000000001600000000000000000000000000000000000000142183323 18062416361508006354700000000004000 \n" + "210072994505161226627780******038400020161226+00000000007890000 469596 26010500000000000001600000000000000000000000000000000000000142183323 18072816361508006354700000000005000 \n" + "210072994505161226627780******473200020161226+00000000016410000 710137 26011300000000000001600000000000000000000000000000000000000142183323 18215316361508006354700000000006000 \n" + "210072994505161226627780******970100020161226+00000000028110000 722260 26011400000000000001600000000000000000000000000000000000000142183323 18223916361508006354700000000007000 \n" + "210072994505161226627780******374300020161226+00000000033050000 103822 26012700000000000001600000000000000000000000000000000000000142183323 18471816361508006354700000000008000 \n" + "210072994505161226627780******035100020161226+00000000036060000 206415 26013200000000000001600000000000000000000000000000000000000142183323 18541516361508006354700000000009000 \n" + "110072994505161226 01161226161227000000+0000000019307-0000000000350+0000000000000+0000000018957010400461000030090036750000000671000000 161226 0000000000000 000000000+0000000000000007163615090044288000000001820000000000242183323071 \n" + "210072994505161226627780******938900020161226+00000000038580000 241875 26013300000000000001600000000000000000000000000000000000000142183323 18564416361509004428800000000001000 \n" + "210072994505161226627780******276500020161226+00000000036360000 404956 26014200000000000001600000000000000000000000000000000000000142183323 19083416361509004428800000000002000 \n" + "210072994505161226627780******053300020161226+00000000052870000 562554 26015000000000000001600000000000000000000000000000000000000142183323 19202816361509004428800000000003000 \n" + "210072994505161226627780******400200020161226+00000000018340000 761322 26016100000000000001600000000000000000000000000000000000000142183323 19363216361509004428800000000004000 \n" + "210072994505161226509091******810000020161226+00000000041850000 386308 26016900000000000001600000000000000000000000000000000000000142183323 19500816361509004428800000000005000 \n" + "210072994505161226506727******110300020161226+00000000005070000 386367 26017500000000000001600000000000000000000000000000000000000142183323 19560716361509004428800000000006000 \n" + "900000000029 \n"; final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE); 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