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
  • Match everything enclosed
    (?:...)
  • Capture everything enclosed
    (...)
  • 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"
"
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 = "(?!\\d\\s\\bPP\\b)(?!\\d\\s\\bpp\\b)(?!\\d\\s\\bGa\\b)(?!\\d\\s\\bMa\\b)(?=\\d\\s\\w)"; final String string = "1 Abdullaev, R.N.. Akhmedzhanov. M.A. and Borisov, O.M., 1972, Occurrence of oncolites in the Precambrian of northern Nuratau. Uzb. Geol. Zh.. 1972 (1): 111 (in Russian). 2 Abelson, P.H.. 1967. Conversion of biochemicals to kerogen and n-paraffins. In: P.H. Abelson (Editor). Researches in Geochemistry, 2. Wiley. New York. N.Y.. pp. 63-86. 3 Abelson. P.H. and Hare, P.E.. 1969. Recent amino acids in the Gunflint chert. Carnegie Inst. Wash , Yearb.. 67: 208-210. 4 Abelson. P.H. and Hare, P.E., 1970. Uptake of amino acids by kerogen. Carnegie Inst. Wash.. Yearb., 68: 297-303. 5 Abelson, P.H. and Hare, P.E.. 1971. Reactions of amino acids with natural and artificial humus and kerogens. Carnegie Inst. Wash., Yearb.. 69: 327-334. 6 Abelson, P.H. and Hoering. T.C.. 1961. Carbon isotope fractionation in formation of amino acids. Proc. Natl. Acad. Sci. US.. 47: 623-632. 7 Ablizin. B.D.. Kurbatskiy. A.M. and Krylov, I.N., 1969. Upper Precambrian stratigraphy in the north Urals western sector. Izu. Akad. Nauk S.S.S.R., Ser. Geol., 1969 (9): 108-113 (in Russian). 8 Achauer, C.W.. 1967. Petrography of a reef complex in Lower Cretaceous James Limestone. Bull. Am. Assoc. Pet. Geol., 51: 452 (abstract). 9 Achauer. C.W. and Johnson, J.H., 1969. Algal strornatolites in the James Reef Complex (Lower Cretaceous). Fairway Field, Texas. J. S e dim e nt. P et r ol.. 39: 1466. 10 Ackman, R.G.. Tocher, C.S. and McLachlan. J.. 1968. Marine phytoplankter fatty acids. J. Fish. Res. Board Can., 25: 1603-1620. 11 Adolphe. J.-P.. 1970. Etude comparde des calcins en choux fleurs du Moyen Nord Canadien, de France et du Liban. C.R. Acad. Sci., Paris, 270: 1080-1083. 12 Adolphe, J.-P., 1973. The carbonate encrustations of the Pont du Gard Aqueduct, France. C.R. Acad. Sci., Paris, Ser. D. 277(21): 2329-2332 (in French). 1341 Adolphe, J.-P. and Rofes, G.. 1973. Calcareous concretions from the Levri6re. a tributary of the Epte River, subtributary of the Seine. Assoc. Fr. Etud. Quaternaire. Bull.. lO(35): 79-87 (in French). 14 Ahr, W.M.. 1967. Origin and Paleoenvironment of some Cambrian Algal Reefs, Mason County Area, Texas. Thesis, Rice University, Houston, Texas, 104 PP. (UNv. Microfilms, Ann Arbor. 67-13.049.) 15 Ahr. W.M.. 1969. Paleoenvironment. algal structures. and fossil algae in Upper Cambrian of central Texas. Bull. Am. Assoc. P et. G e ol.. 53(3): 703 (Abstract)."; final String subst = ""; 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