Regular Expressions 101

Save & Share

  • Regex Version: ver. 6
  • 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 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"
"
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 = "(at the[\\n| ]|from the\\n|at[\\n| ]|faculty of the[\\n| ]|faculty of\\n)(\\w.+[\\n]?\\w+[ ]?\\w+[ ]?\\w+[ ]?\\w+[ ]?\\w+[^(Jan(uary)?|Sep(tember)?(\\s\\d{4})?|(,)?|author?|(fulfillment)?|laminates]\\w+)"; final String string = "MIT Sample:\n" + "SOME ASPECTS OF RADIATION INDUCED NUCLEATION IN WATER\n" + "by\n" + "Chih-Ping Tso\n" + "B.Tech., Loughborough University of Technology, United Kingdom\n" + "(1968)\n" + "Submitted in Partial Fulfillment of\n" + "the Requirements for the Degree of\n" + "Master of Science\n" + "at the\n" + "Massachusetts Institute of Technology\n" + "August 1970\n" + "Signature of Author\n" + "Department of Nuclear Engineering\n" + "Certified by\n" + "Thesis Supervisor\n" + "Accepted by\n" + "Chairman, Departmental Committee\n" + "Archives on Graduate Students\n" + "MASS. INST. TECH.\n" + "--------------------------------------------------------------------------------\n" + "MIT Sample:\n" + "PROCEDURES AS A PEPPESFNTATICN FOR DATA\n" + "IN A COMPUTER PROGRAM FOR UNDERSTANDING\n" + "NATURAL LANGUAGE\n" + "by\n" + "Terry Winograd\n" + "P.A., The Colorado College\n" + "(1966)\n" + "SUBMITTED IN PARTIAL FULFILLMENT\n" + "OF THE REQUIREMENTS FOR THE\n" + "DEGREE OF DOCTOR OF\n" + "PHILOSOPHY\n" + "at the\n" + "MASSACHUSETTS INSTITUTE OF\n" + "TECHNOLOGY\n" + "August, 1970\n" + "Signature of Author\n" + "Department of Mathematics August 24, 1970\n" + "Certified by\n" + "Thesis Supervisor\n" + "Accepted by\n" + "Chairman, Departmental Committee\n" + "on Graduate Students\n" + "MASS. INST.TECH \n" + "SEP 29 1970\n" + "LIBRARIES\n" + "------------------------------------------------------------------------------\n" + "MIT Sample:\n" + "AIR RIGHTS DEVELOPMENT OF URBAN TRANSIT CORRIDORS\n" + "by\n" + "Steven C. Hayes\n" + "B.S. BOSTON UNIVERSITY\n" + "1971\n" + "Submitted in partial fulfillment of\n" + "the requirements for the\n" + "Degree of Master of Architecture\n" + "at the\n" + "MASSACHUSETTS INSTITUTE OF TECHNOLOGY\n" + "January, 1975\n" + "Author\n" + "Department of Architecture, Janurary 22, 1975\n" + "Certified by\n" + "Thesis Supervisor\n" + "Accepted by\n" + "Chairman, Departmental Committee on Graduate Students\n" + "Archives\n" + "MASS.INST. TECH.\n" + "FEB 13 1975\n" + "LIBRARIES\n" + "--------------------------------------------------------\n" + "MIT Sample:\n" + "BUILDINGS AS SYS TEMS\n" + "by\n" + "Ary M. Pedju\n" + "Ir. Ars., Institut Teknologi Bandung,\n" + "Bandung, Indonesia, 1963\n" + "Submitted in partial fulfillment of the\n" + "requirements for the degree of Master in\n" + "Architecture at the Massachusetts Institute\n" + "of Technology, June 1965.\n" + "Submitted by\n" + "Ary M. Pedju\n" + "Certified by\n" + "Eduardo F. Catalano\n" + "Thesis Advisor\n" + "Accepted by\n" + "Lawrence B. Anderson\n" + "Head, Department of Architecture\n" + "----------------------------------------------------------------------\n" + "MIT Sample:\n" + "PROCEDURES AS A PEPPESFNTATICN FOR DATA\n" + "IN A COMPUTER PROGRAM FOR UNDERSTANDING\n" + "NATURAL LANGUAGE\n" + "by\n" + "Terry Winograd\n" + "P.A., The Colorado College\n" + "(1966)\n" + "SUBMITTED IN PARTIAL FULFILLMENT\n" + "OF THE REQUIREMENTS FOR THE\n" + "DEGREE OF DOCTOR OF\n" + "PHILOSOPHY\n" + "at the\n" + "MASSACHUSETTS INSTITUTE OF\n" + "TECHNOLOGY\n" + "August, 1970\n" + "Signature of Author\n" + "Department of Mathematics August 24, 1970\n" + "Certified by\n" + "Thesis Supervisor\n" + "Accepted by\n" + "Chairman, Departmental Committee\n" + "on Graduate Students\n" + "MASS. INST.TECH \n" + "SEP 29 1970\n" + "LIBRARIES\n" + "---------------------------------------------------------------------------\n" + "MIT Sample:\n" + "STALL PROPAGATION IN AXIAL COMPRESSORS\n" + "ALAN H. STENNING\n" + "B.Sc., University of Glasgow\n" + "(1950)\n" + "S.M., Massachusetts Institute of Technology\n" + "(1951)\n" + "SUBMITTED IN PARTIAL FULFILLMENT\n" + "OF THE REQUIREMENTS FOR THE\n" + "DEGREE OF DOCTOR OF SCIENCE\n" + "at the\n" + "MASSACHUSETTS INSTITUTE OF TECHNOLOGY\n" + "June, 1955\n" + "Signature of Author\n" + "Department of Mechanical Engineering, May 10, 1955\n" + "Certified by\n" + "Thesis Supervisor\n" + "Accepted by\n" + "Chairman, Departmental Committee on Graduate Students\n" + "------------------------------------------------------------------------------\n" + "A HEADQUARTERS FOR THE WORLD HEALTH ORGANIZATION\n" + "IN GENEVA, SWITZERLAND\n" + "by\n" + "Johannes Philipp Holschneider\n" + "Diplom Ingenieur, 1959\n" + "Technische Hochschule\n" + "Karlsruhe/Rhein, Germany\n" + "SUBMITTED IN PARTIAL FULFILLMENT OF\n" + "THE REQUIREMENTS FOR THE DEGREE\n" + "OF MASTER IN ARCHITECTURE at the\n" + "MASSACHUSETTS INSTITUTE OF TECHNOLOGY\n" + "Signature of Author\n" + "Certified by\n" + "A Thesis Supervisor\n" + "Accepted by\n" + "Chairman, Departmental Committee\n" + "on Graduate Students\n" + "----------------------------------------------------\n" + "MIT Sample:\n" + "AN INVESTIGATION OF THE POWER SPECTRAL DENSITY OF ATMOSPHERIC TURBULENCE\n" + "by\n" + "GERHARDT C. CLEMENTSON\n" + "B.S. U.S. Military Academy, 1942\n" + "M.S. California Institute of Technology, 1945\n" + "S.M. Massachusetts Institute of Technology, 1948\n" + "SUBMITTED IN PARTIAL FULFILLMENT OF THE\n" + "REQUIREMENTS FOR THE DEGREE OF\n" + "DOCTOR OF SCIENCE\n" + "at\n" + "MASSACHUSETTS INSTITUTE OF TECHNOLOGY\n" + "1950\n" + "Signature of Author\n" + "Thesis Supervisor\n" + "Chairman, Departmental Committee on Graduate Students\n" + "------------------------------------------------------------------\n" + "MIT Sample:\n" + "OXIDATION STUDIES\n" + "IN\n" + "METAL-CARBON SYSTEMS\n" + "by\n" + "Watt Wetmore Webb\n" + "S.B. Massachusetts Institute of Technology 1947\n" + "Submitted in Partial Fulfillment of the\n" + "Requirements for the Degree of\n" + "Doctor of Science\n" + "from the\n" + "Massachusetts Institute of Technology\n" + "1955\n" + "Signature of Author\n" + "Department of Metallurgy\n" + "May 16, 1955\n" + "Professors in Charge of Research\n" + "Chairman, Departmental Committee\n" + "on Graduate Students\n" + "-------------------------------------------------------------------\n" + "MIT Sample:\n" + "NEW YWCA BUILDING,\n" + "PITTSBURGH, PA.\n" + "A thesis is submitted in partial fulfillment of the requirements\n" + "for the degree of Master in Architecture at Massachusetts \n" + "Institute of Technology\n" + "Submitted by\n" + "Visvaldis Paukulis\n" + "B.Arch., State Inst. of\n" + "Technology, Riga, Latvia\n" + "To\n" + "Lawrence B. Anderson\n" + "Head, Department of Architecture, M.I.T.\n" + "-------------------------------------------------------------------\n" + "MIT Sample:\n" + "THE CORROSION OF STEEL IN SALINE\n" + "SOLUTIONS OF HYDROGEN SULFIDE\n" + "by\n" + "SANFORD J. NEUHAUS\n" + "Submitted in Partial Fulfillment of the\n" + "Requirements for the S.B. Degree\n" + "from the\n" + "MASSACHUSETTS INSTITUTE OF TECHNOLOGY\n" + "1945\n" + "Signature of Author\n" + "Department of Chemical Engineering, June, 1945\n" + "Signature or Thesis Supervisor\n" + "-----------------------------------------------------------------\n" + "MIT Sample:\n" + "THE CHROMIUM-OXYGEN-HYDROGEN EQUILIBRIUM IN LIQUID IRON\n" + "by\n" + "HSIN-MIN CHEN\n" + "B. S., National Tsinghua University\n" + "1935\n" + "Submitted in Partial Fulfillment of the\n" + "Requirements for the Degree of\n" + "DOCTOR OF SCIENCE\n" + "from the\n" + "Massachusetts Institute of Technology\n" + "1945\n" + "Signature of Author\n" + "Department of Metallurgy\n" + "June 4, 1945 \n" + "Signature of Professor\n" + "in Charge of Research \n" + "Signature of Chairman\n" + "Department Committee\n" + "on Graduate Students\n" + "--------------------------------------------------------------\n" + "MIT Sample:\n" + "A CRITICAL SURVEY OF PUBLISHED\n" + "PHYSICAL PLANNING PRINCIPLES\n" + "by\n" + "Thomas A. Reiner\n" + "B.A., Swarthmore College\n" + "(1952)\n" + "Submitted in partial fulfillment of the requirements\n" + "for the degree of Master in City Planning\n" + "at the\n" + "Massachusetts Institute of Technology\n" + "(May 1955)\n" + "Head, Department of City and Regional Planning\n" + "Thesis Advisor\n" + "Author\n" + "----------------------------------------------------------------------\n" + "Virginia Tech Sample:\n" + "THEY EXPERIENCE OF THE CATHOLIC DIOCESE OF RICHMOND\n" + "WITH ESEA TITLE I, APRIL 1965 -- DECEMBER 1976\n" + "by\n" + "Richard J.Fenchak \n" + "Dissertation submitted to the faculty of\n" + "Virginia Polytechnic Institute and State University\n" + "in partial fulfillment of the requirements for the degree of\n" + "DOCTOR OF EDUCATION\n" + "in\n" + "Educational Administration\n" + "APPROVED:\n" + "David J. Parks (Co-Chair) Thomas C. Hunt (Co-Chair)\n" + "M. David Alexander James W. Michaels\n" + "Kenneth E. Underwood\n" + "January, 1986\n" + "Blacksburg, Virginia\n" + "----------------------------------------------------\n" + "Virginia Tech Sample:\n" + "ASSESSMENT OF A MENTOR PROGRAM\n" + "ON SELF-CONCEPT AND ACHIEVEMENT VARIABLES\n" + "OF MIDDLE SCHOOL UNDERACHIEVERS\n" + "by\n" + "Helene Aiello\n" + "Dissertation submitted to the faculty of the Virginia\n" + "Polytechnic Institute and State University in partial\n" + "fulfillment of the requirements for the degree of\n" + "Doctor of Education\n" + "in\n" + "Administration and Supervision\n" + "Of\n" + "Special Education\n" + "APPROVED:\n" + "Philip R. Jones, Chairman Kenneth Underwood\n" + "Sylvia Auton\n" + "Shirley Jones Ronald McKeen\n" + "February 22, 1988\n" + "Blacksburg, Virginia\n" + "---------------------------------------------------\n" + "Virginia Tech Sample:\n" + "Synthesis, Characterization and Kinetic Investigations of Heterophase Materials\n" + "Prepared Using Group Transfer Polymerization\n" + "by\n" + "Ann Marie Hellstern\n" + "Dissertation submitted to the faculty of the Virginia Polytechnic Institute and\n" + "State University in partial fulfillment of the requirements for the degree of\n" + "Doctor of Philosophy\n" + "in\n" + "Chemistry\n" + "Approved By:\n" + "J.E. McGrath\n" + "G. L. Wilkes J. F. Wolfe\n" + "B.E. Hanson H.M. Bell\n" + "-----------------------------------------------------------\n" + "Virginia Tech Sample:\n" + "THE KINETICS AND THERMODYNAMICS\n" + "OF CLAY MINERAL REACTIONS\n" + "by\n" + "John Alan Chermak\n" + "Dissertation submitted to the faculty of\n" + "Virginia Polytechnic Institute and State University\n" + "in partial fulfillment of the requirements of the degree of\n" + "DOCTOR OF PHILOSOPHY\n" + "In\n" + "Geology\n" + "APPROVED:\n" + "J. D. Rimstidt, Chairman\n" + "L. W. Zelazny J. R. Craig\n" + "R. J. Bodnar S. C. Eriksson\n" + "November, 1989\n" + "Blacksburg, Virginia\n" + "-------------------------------------------------------------\n" + "Virginia Tech Sample:\n" + "STRATEGIES AND TACTICS TO ACCESS INTUITION:\n" + "A LOOK AT THE MOMENT OF SOLUTION\n" + "by\n" + "Linda E. Morris\n" + "Dissertation submitted to the faculty of the\n" + "Virginia Polytechnic Institute and State University\n" + "in partial fulfillment of the requirements for the degree of\n" + "DOCTOR OF EDUCATION\n" + "Adult Continuing Education\n" + "Approved:\n" + "Dr. Marcie Boucouvalas, Chairperson\n" + "Dr. Neal E. Chalofsky Dr. Hugo A. Keesing\n" + "Dr. Ronald L. McKeen Dr. Orion F. White\n" + "March 1, 1990\n" + "Blacksburg, Virginia\n" + "----------------------------------------------------------\n" + "Virginia Tech Sample:\n" + "PREDICTION MODEL FOR THE ONSET OF EDGE-EFFECT DELAMINATION\n" + "at holes in composite laminates\n" + "by\n" + "Doron Shalev\n" + "Dissertation submitted to the faculty of the\n" + "Virginia Polytechnic Institute and State University\n" + "in partial fulfillment of the requirements for the degree of\n" + "DOCTOR OF PHILOSOPHY\n" + "in\n" + "Engineering Science and Mechanics\n" + "APPROVED:\n" + "K. L. Reifsnider\n" + "C. W. Smith R. T. Haftka\n" + "R. M. Jones R. A. Heller\n" + "July, 1988\n" + "Blacksburg, Virginia"; 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