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

$re = '/(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\s(\d\d?)(st|nd|rd|th)?,?\s(\d{4})|(\d\d?)[\.\/-](\d\d?)[\.\/-](\d{4})/m'; $str = '03.24.2014 Jan 13 2021 January 29, 2007 Jan 9 2003 12/25/2008 July 7th, 2022 03-16-2000 08-28-2020 June 21 2019 04-24-2008 October 31st 2018 June 20, 2000 August 29th 2005 Dec 12th, 2019 April 5 2004 Feb 7 2020 July 9th, 2011 Aug 18 2015 01.27.2020 December 27, 2022 04-05-2005 07/19/2001 08/21/1999 August 31st, 2004 November 18th 2015 Feb 25 2006 February 27th 2011 September 29th, 1999 Nov 13, 2017 Aug 19th 2014 Nov 24 1999 Oct 25 2015 11/01/2019 02/11/2017 11.30.2019 05.26.2002 Jan 14 1998 May 5, 1998 04-24-1998 November 23 2006 Mar 21, 1999 April 6, 2013 Jun 4th, 2012 Oct 16th, 2000 08/07/2021 May 8, 2003 October 30th, 2021 07/27/1998 03.30.2007 08/12/2005 May 23 2020 01/18/2019 09/04/2013 December 17, 2022 06.30.2012 Jul 23rd 2022 10.28.1998 February 16th 1998 05-20-2008 September 27th, 2002 03.27.2004 08/11/2015 May 29th, 2006 02-19-2005 02/08/2018 June 14, 2003 January 18th, 2000 Jun 9th 2022 02.12.2003 06/15/2015 April 16th, 2001 April 13th, 2011 Nov 7, 1998 02.19.2015 03/18/2009 12/19/2005 July 25th, 1998 08.06.2022 October 5, 2016 October 1, 2022 03-13-2013 06-03-1999 Nov 29th 2005 Jul 9, 2014 10-10-1999 August 19 2016 Apr 5, 2016 09.26.1999 10/15/2007 12.04.2018 12-08-2008 Jul 13, 2022 12.23.2006 December 8, 2011 June 4th 2004 10.07.2007 June 19th 2002 09.05.2011 December 15, 2009 12/17/2007 08-25-2017 September 13, 2000 11-29-2006 12-11-2000 01/25/2016 09/13/2014 Dec 30 2017 05/28/2018 January 31 2020 November 7th 2002 July 14 2008 08.31.2009 October 25 2018 01/09/1999 09/16/2007 04/01/2013 12-15-2000 Oct 16 2004 10.25.2009 Aug 7 2001 April 13th 2020 April 11th 2001 02/20/2011 Aug 4 2008 Jul 25 2017 November 1, 2010 July 7 2000 December 15, 2013 12.04.2018 03/21/2014 11/15/2004 September 6th, 2003 May 15th, 2010 February 7 2011 06/10/2021 02-13-2016 02.10.2012 08-20-1998 Aug 24, 2007 04.27.2014 03/08/2019 09-09-2020 September 10th, 2022 May 11th, 2002 11/05/2015 01-29-2003 Aug 27th, 2000 Oct 11, 2013 12/12/2002 Nov 16 2007 October 13th, 2008 10-12-2017 02/16/1999 04.13.2013 Aug 19, 2020 February 9th, 2018 Sep 27, 2002 April 27th, 2005 February 17, 2005 Apr 6 1998 July 17, 2020 10/22/2000 11/29/2019 Jan 5 2018 08/12/1998 10.07.1998 07/21/2021 03.22.2006 04-19-2002 Feb 26th, 2022 Mar 18 2017 February 10, 2013 September 24, 2021 07-14-2003 Feb 1st, 2019 March 23, 2022 11/22/2014 May 10 2014 Mar 13th, 2008 05.27.2014 Jun 22, 2010 Jun 26th 2020 Sep 7, 2002 June 19 2004 03-26-2015 07.27.2005 02/24/1998 February 13th 2010 08-18-2012 May 27 1999 August 7th 2001 07.27.2001 January 25 2006 07.31.2003 November 1st, 2007 04.13.2010 11.03.2021 Oct 6, 2019 February 10 2015 01.11.2000 05.16.2016 11.16.2019 01-16-2003 December 31st 2018 04.15.2014 Jul 17th 2007 11-07-2021 05-10-2007 02-01-2007 May 31st, 2004 July 4th 2018 Jun 28 2018 Nov 17 2002 Jun 24, 2006 March 26 2022 10/18/1998 Jul 2nd 1998 March 25th, 2020 Jul 30th 2021 08.24.2017 October 8, 2006 10.24.2002 May 8 2020 Apr 16th 2006 10.20.2005 05/05/2001 10/21/2020 05/20/2020 11/09/2015 12-16-2011 Nov 8, 2019 02-10-2015 September 26th 2012 May 11th 2020 Dec 23rd, 2005 May 14th 1998 01.16.2004 Oct 28 1999 July 5th 2006 05-09-2018 10.28.2017 Jun 1, 2004 Feb 3rd, 2002 07.31.2004 Jan 26 2009 12/04/2009 Jan 21st, 2020 February 18 2015 10.28.2018 Oct 16th, 2020 February 23, 2002 08-29-2001 August 22 2002 June 22nd, 2009 09.06.2006 Oct 14th 2003 October 24th, 2005 09-30-2000 September 24th 2007 11-19-2020 03-21-2004 02/24/2004 08/30/2011 September 27 2003 Aug 3 2003 August 15, 2014 October 17 2019 June 26th 2011 05.16.2021 12-21-2018 August 19th 2003 June 2nd, 2022 November 11th, 1999 August 10 2012 Jan 28th 2019 Jun 10th 2012 Jan 18th, 2014 October 30, 2015 April 21 2000 August 18 2002 September 1, 2014 Sep 9th 2003 09-16-2007 May 3rd, 2003 March 16, 2016 Jul 24 2002 08-19-1999 February 3, 2013 January 17 2010 11-12-2002 January 29 2006 04.24.2004 Aug 25, 2002 October 16 2001 August 15 2022 06-20-2011 06-27-2004 December 28, 2015 Apr 1st 2004 Sep 21, 2002 Oct 19th, 2007 August 12, 1999 January 29, 2012 04.01.1998 10.06.2021 October 31, 2012 April 28th, 2017 March 5, 2019 04/01/2016 03.12.2016 Dec 23rd, 2010 02-15-2022 January 14 2016 05/23/2019 07.10.2012 Sep 25th, 2001 10/14/2003 March 30th 2021 April 25th, 1999 Mar 20th 2015 Apr 17th, 2011 11-30-2007 04/21/2001 08/07/2006 November 15 2002 11-30-2014 07/26/2013 February 8, 2020 06.17.1999 01/13/2002 10/19/2009 12-20-2020 March 5 2001 10.05.2010 Feb 22nd, 2020 May 25th, 2013 12-06-1998 09.05.2013 05.09.2014 12/30/2016 May 2 2003 07.10.2006 07.17.2011 11/04/2006 April 29 2018 03-27-2005 May 1, 2006 02.23.2002 03.02.1998 12/12/2002 08-08-2002 08/31/2018 05-10-2011 07.10.2015 12.02.2012 Aug 4, 2022 06.12.2021 01.13.2020 October 1st 1998 August 19, 2013 Mar 18 2021 06.18.2009 08.12.2012 10-03-2022 04-21-2018 10/30/2015 May 14 2019 05/22/2012 02.18.2014 03.20.2022 01.09.2006 March 2 2014 Mar 16 2011 10-08-1999 09-14-2010 11.23.2002 April 28th, 2004 04-12-2007 June 1st 2003 July 2nd 2007 December 14, 2016 10/26/2019 February 11th 2015 February 12th, 2018 01/08/2004 September 22nd, 2004 August 17th, 2000 November 22nd 2021 June 10th 2003 Jul 17th 1999 09-01-2014 July 21st 2015 January 11 2013 03/04/2005 02-08-2018 Mar 20, 2001 04/03/2016 September 11, 2021 01/30/2016 April 8 2009 05/08/2010 Jan 15th 2008 02-13-2022 Apr 15th, 2016 Sep 4 2020 Nov 10, 2008 March 30 2014 07.27.2005 01.27.2021 June 9th 2021 Feb 23rd, 2020 06.05.2015 02-23-2000 Feb 12, 2020 May 1st 1998 03/08/2017 03-27-2007 July 13, 1998 01/01/2000 Apr 2, 1998 02.14.2014 Mar 22 2005 Jan 4 2012 08-28-2015 Jan 21st, 2015 Jul 7th, 2006 05-04-2004 Apr 4, 1999 11/04/2016 10-26-2009 June 22 2006 08/24/2022 12-14-2012 Feb 28, 2001 09/21/2000 Aug 24, 2016 October 22nd, 2001 June 21, 2005 August 27th, 2018 Feb 26th, 2020 February 14th, 2012 06.01.2008 07/20/2017 02.10.2022 July 27th 2009 10-08-2016 09/03/2005 Apr 12, 2005 Nov 22 2016 Mar 24, 2002 Sep 5, 1999 March 29th 1999 Feb 4, 1999 08/17/2002 November 13 2014 02-08-2013 Aug 1, 2009 Oct 8, 2015 03-20-2003 Mar 16, 2012 Nov 4 2017 Jan 28th, 2008 10-13-2017 Oct 24th 2012 Jul 11, 2003 Apr 17 2013 November 20th, 2020 09.06.2013 June 2, 2012 09/13/2010 Sep 28th, 2000 07-06-2005 Dec 13 2007 September 4 2004 June 20, 2010 12/28/2013 Mar 24 2004 March 8, 2012 02-18-2008 April 24 2013 02-27-2003 03.10.2022 Jul 18 2020 02-05-2004 03/26/2014 September 18th 1999 04/04/2021 June 10th, 2014 Jul 6th, 2007 April 21st 2022 09-17-2012 09/17/1999 03.22.1998 06/15/2000 January 11 2008 March 5, 1999 11/07/2011 04/22/2017 05-21-2012 Aug 2 2011'; preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0); // Print the entire match result var_dump($matches);

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 PHP, please visit: http://php.net/manual/en/ref.pcre.php