Regular Expressions 101

Save & Manage Regex

  • Current Version: 1
  • Save & Share
  • Community Library

Flavor

  • PCRE2 (PHP)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java
  • .NET 7.0 (C#)
  • Rust
  • PCRE (Legacy)
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests
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
Processing...

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 = "^(?P<name>[a-zA-Z0-9&@\\-\\.\\,\\(\\)\\[\\} ]*)[ \\t]*(?P<language>[A-Z]{1})[\\t ]*(?P<lab_info>\\0|[a-zA-Z0-9&@\\.\\,\\(\\)\\[\\} ]*)[ \\t]*[-]{0,1}[ \\t]*(?P<day>\\d{2})\\/(?P<month>\\d{2})\\/(?P<year>\\d{4})[,][ \\t]*(?P<day_in_words>[a-zA-Z]*)[ \\t]*(?P<from>\\d{2}[:]\\d{2})[ \\t]*[-][ \\t]*(?P<to>\\d{2}[:]\\d{2})[ \\t]*(?P<center>[a-zA-Z0-9&@\\-\\.\\,\\(\\)\\[\\}]*)[ \\t]*"; final String string = "Day School 1 E - 18/02/2018, Sun 15:30 - 17:30 CL \n" + "Day School 1 E - 20/02/2018, Tue 10:30 - 12:30 KN \n" + "Lab 1 E CLE01 24/05/2018, Thu 09:30 - 16:30 CL \n" + "Lab 1 E KNE01 14/06/2018, Thu 09:30 - 16:30 KN \n" + "CA-Test 1 E - 12/07/2018, Thu 12:00 - 13:15 RC \n" + "Day School 2 E - 28/07/2018, Sat 13:00 - 15:00 KN \n" + "Day School 2 E - 28/07/2018, Sat 13:00 - 15:00 CL \n" + "Day School 3 E - 28/07/2018, Sat 15:00 - 17:30 CL \n" + "Day School 3 E - 28/07/2018, Sat 15:30 - 17:30 KN \n" + "Lab 2 E CLE01 03/08/2018, Fri 09:30 - 16:30 CL \n" + "Lab 2 E KNE01 04/09/2018, Tue 09:30 - 16:30 KN \n" + "CA-Test 2 E - 06/10/2018, Sat 12:00 - 13:15 RC \n" + "Tutor Marked Assignment Due 1 E - 17/10/2018, Wed 09:30 - 16:30 CL \n" + "Lab 3 E CLE01 24/10/2018, Wed 09:30 - 16:30 CL \n" + "Lab 3 E KNE01 02/11/2018, Fri 09:30 - 16:30 KN \n" + "Day School 4 E - 04/11/2018, Sun 15:30 - 17:30 CL \n" + "Day School 4 E - 09/11/2018, Fri 13:00 - 15:00 KN \n" + "Lab Evaluation 1 E - 29/11/2018, Thu 09:30 - 12:30 CL \n" + "Final Examination 1 E - 27/01/2019, Sun 09:30 - 12:30 RC \n" + "AGI3535 Land and soil tillage management \n" + "Eligibility Criteria : AVG(CAT)0.5 + (TMA)0.1 + AVG(LAB)0.4 >= 40 \n" + " AVG(LAB)1 >= 40 \n" + "Note : *AVG(LAB)=(LAB Reports)0.4+(Lab Evaluation)0.6 \n" + "Academic Coordinator/s : \n" + " \n" + " \n" + " Ms. B.S.G. Chandrasekera 0112881442 / 442 bscha@ou.ac.lk \n" + "Course Coordinator/s : \n" + " \n" + " \n" + "Activity Description M Group Date Time Centre \n" + "Day School 1 E - 18/02/2018, Sun 08:00 - 10:00 KN\n\n" + "2\n\n" + " \n\n" + " [AGI3535 Land and soil tillage management]\n\n\n" + " \n\n\n" + " Day School 1 E - 18/02/2018, Sun 08:00 - 10:00 CL \n" + "Lab 1 E CLE01 04/06/2018, Mon 09:30 - 16:30 CL \n" + "Lab 1 E KNE01 12/06/2018, Tue 09:30 - 16:30 KN \n" + "CA-Test 1 E - 14/07/2018, Sat 09:00 - 10:15 RC \n" + "Day School 2 E - 18/08/2018, Sat 08:00 - 10:00 KN \n" + "Day School 2 E - 18/08/2018, Sat 08:00 - 10:00 CL \n" + "Lab 2 E CLE01 30/08/2018, Thu 09:30 - 16:30 CL \n" + "Lab 2 E KNE01 07/09/2018, Fri 09:30 - 16:30 KN \n" + "CA-Test 2 E - 07/10/2018, Sun 09:00 - 10:15 RC \n" + "Tutor Marked Assignment Due 1 E - 17/10/2018, Wed 09:30 - 16:30 CL \n" + "Day School 3 E - 24/11/2018, Sat 13:00 - 15:00 CL \n" + "Day School 3 E - 24/11/2018, Sat 13:00 - 15:00 KN \n" + "Lab 3 E CLE01 26/11/2018, Mon 09:30 - 16:30 CL \n" + "Lab 3 E KNE01 27/11/2018, Tue 09:30 - 16:30 KN \n" + "Lab Evaluation 1 E - 30/11/2018, Fri 09:30 - 12:30 CL \n" + "Final Examination 1 E - 14/01/2019, Mon 09:30 - 12:30 RC \n" + "AGI3536 Post-harvest biology and technology I \n" + "Eligibility Criteria : AVG(CAT)0.5 + (TMA)0.1 + AVG(LAB)0.4 >= 40 \n" + " AVG(LAB)1 >= 40 \n" + "Note : *AVG(LAB)=(LAB Reports)0.4+(Lab Evaluation)0.6 \n" + "Academic Coordinator/s : \n" + " \n" + " \n" + " Mr.P. K. J. de Mel ext. 396 / 0112881396 pkmel@ou.ac.lk \n" + "Course Coordinator/s : \n" + " \n" + " \n" + " Miss.M. D. Jayasinghe 442 / 0112881442 mdjayasinghe91@gmail.com \n" + "Activity Description M Group Date Time Centre \n" + "Day School 1 E - 23/06/2018, Sat 10:30 - 12:30 KN \n" + "Day School 1 E - 23/06/2018, Sat 10:30 - 12:30 CL \n" + "Lab 1 E - 25/06/2018, Mon 09:30 - 16:30 CL \n" + "Lab 1 E - 26/06/2018, Tue 09:30 - 16:30 KN \n" + "CA-Test 1 E - 17/07/2018, Tue 09:00 - 10:15 RC \n" + "Day School 2 E - 19/08/2018, Sun 10:30 - 12:30 KN \n" + "Day School 2 E - 19/08/2018, Sun 10:30 - 12:30 CL \n" + "Lab 2 E - 23/08/2018, Thu 09:30 - 16:30 CL \n" + "Lab 2 E - 31/08/2018, Fri 09:30 - 16:30 KN \n" + "CA-Test 2 E - 09/10/2018, Tue 09:00 - 10:15 RC \n" + "Tutor Marked Assignment Due 1 E - 17/10/2018, Wed 09:30 - 12:30 CL \n" + "Day School 3 E - 04/11/2018, Sun 10:30 - 12:30 KN \n" + "Day School 3 E - 04/11/2018, Sun 10:30 - 12:30 CL \n" + "Lab 3 E - 22/11/2018, Thu 09:30 - 16:30 CL\n\n" + " \n" + "Lab 1 (Session 2) E CLE05 25/05/2018, Fri 09:00 - 16:00 CL \n" + "Day School 2 E - 26/05/2018, Sat 10:30 - 12:30 CL \n" + "Lab 1 E CLE06 11/06/2018, Mon 09:00 - 16:00 CL \n" + "Lab 1 (Session 2) E CLE06 12/06/2018, Tue 09:00 - 16:00 CL \n" + "Lab 1 E CLE07 14/06/2018, Thu 09:00 - 16:00 CL \n" + "Lab 1 (Session 2) E CLE07 15/06/2018, Fri 09:00 - 16:00 CL \n" + "Lab 1 E CLE08 18/06/2018, Mon 09:00 - 16:00 CL \n" + "Lab 1 (Session 2) E CLE08 19/06/2018, Tue 09:00 - 16:00 CL \n" + "CA-Test 1 E - 17/07/2018, Tue 12:00 - 13:15 RC \n" + "Lab 1 E CLE09 25/07/2018, Wed 09:00 - 16:00 CL \n" + "Lab 1 (Session 2) E CLE09 26/07/2018, Thu 09:00 - 16:00 CL \n" + "Lab 1 E CLE10 30/07/2018, Mon 09:00 - 16:00 CL \n" + "Lab 1 (Session 2) E CLE10 31/07/2018, Tue 09:00 - 16:00 CL \n" + "Lab 1 E CLE11 02/08/2018, Thu 09:00 - 16:00 CL \n" + "Lab 1 (Session 2) E CLE11 03/08/2018, Fri 09:00 - 16:00 CL \n" + "Tutor Marked Assignment Due 1 E - 03/08/2018, Fri 09:00 - 16:00 CL \n" + "Lab 1 E CLE12 09/08/2018, Thu 09:00 - 16:00 CL \n" + "Lab 1 (Session 2) E CLE12 10/08/2018, Fri 09:00 - 16:00 CL \n" + "Lab 1 E CLE13 16/08/2018, Thu 09:00 - 16:00 CL \n" + "Lab 1 (Session 2) E CLE13 17/08/2018, Fri 09:00 - 16:00 CL \n" + "Lab 1 E CLE15 22/08/2018, Wed 09:00 - 16:00 CL \n" + "Lab 1 E CLE14 23/08/2018, Thu 09:00 - 16:00 CL \n" + "Lab 1 (Session 2) E CLE15 23/08/2018, Thu 09:00 - 16:00 CL \n" + "Lab 1 (Session 2) E CLE14 24/08/2018, Fri 09:00 - 16:00 CL \n" + "Lab 1 E CLE16 03/09/2018, Mon 09:00 - 16:00 CL \n" + "Lab 1 (Session 2) E CLE16 04/09/2018, Tue 09:00 - 16:00 CL \n" + "Lab 1 E CLE17 06/09/2018, Thu 09:00 - 16:00 CL \n" + "Lab 1 (Session 2) E CLE17 07/09/2018, Fri 09:00 - 16:00 CL \n" + "Day School 3 E - 22/09/2018, Sat 10:30 - 12:30 CL \n" + "Lab 1 E CLE18 01/10/2018, Mon 09:00 - 16:00 CL \n" + "Lab 1 (Session 2) E CLE18 02/10/2018, Tue 09:00 - 16:00 CL \n" + "Lab 1 E CLE19 03/10/2018, Wed 09:00 - 16:00 CL \n" + "Lab 1 (Session 2) E CLE19 04/10/2018, Thu 09:00 - 16:00 CL \n" + "CA-Test 2 E - 09/10/2018, Tue 12:00 - 13:15 RC \n" + "Lab 1 E CLE20 29/10/2018, Mon 09:00 - 16:00 CL \n" + "Lab 1 (Session 2) E CLE20 30/10/2018, Tue 09:00 - 16:00 CL \n" + "Tutor Marked Assignment Due 2 E - 02/11/2018, Fri 09:00 - 16:00 CL \n" + "Online Quiz 1 E - 15/12/2018, Sat 08:00 - 17:30 CL \n" + "Day School 4 E - 05/01/2019, Sat 10:30 - 12:30 CL \n" + "Final Examination 1 E - 06/02/2019, Wed 09:30 - 12:30 RC \n" + "DMX4571 Sensors and actuators\n\n" + "144\n\n" + " \n\n" + " [DMX4571 Sensors and actuators]\n\n\n" + " \n\n" + " \n\n\n" + " Eligibility Criteria : 1B(CAT)0.35 + 2B(CAT)0.15 + AVG(TMA)0.3 + (LAB)0.2 >= 40 \n" + " (LAB)1 >= 50 \n" + "Academic Coordinator/s : \n" + " \n" + " \n"; 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