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

Code Generator

Generated Code

$re = '/^([[(](?P<series>[^_-]+?)[])])?[\s]*?(?P<author>(?! [-]).*?)([\s]+?-[\s]*)(?P<title>[^\(]*?)((?P<comments>[\(](?:[\s]*(((?P<published>[12][\d]{3,3})\s*)((?=([,\)]))))?)?((?P<prepublisher>[\w]*?[,-]?)([,]?[\s]*((?P<publisher>[-|~\'&%$#"!\w\s]*(([a-zA-Z]+)[-|~\'&%$#"!\w\s]*))(?!(([\d-]{11}-?([x]|[\d])[\s]*[\)])))))?(?P<isbn>([,]?[\s]*(?P<isbntag>(?i)ISBN[-]?1(?:(?P<is10>0)|3)?[:\s])?\s*(?(isbntag)(?(is10)((?=[\d-]{11}-[\d|x][\s]*[\)])(?P<isbn10>\d{1,5}[ -]\d{1,7}[ -]\d{1,6}[ -](?:\d|x)))|((?:(?=[\d-]{17}[\s]*[\)])(?P<isbn13>97(?:8|9)[ -]\d{1,5}[ -]\d{1,7}[ -]\d{1,6}[ -]\d))))|(?:(?=(([\d-]{11}-([\d]|[x]))[\s]*[\)]))(?P<ISBN10>\d{1,5}([ -])\d{1,7}[ -]\d{1,6}[ -](?:\d|x))|(?:(?=[\d-]{17}[\s]*[\)])(?P<ISBN13>97(?:8|9)[ -]\d{1,5}[ -]\d{1,7}[ -]\d{1,6}[ -]\d)))))?)(?=([\s]*[,\)])))?(?P<tooManyCommasOrOnlyDigits>.*)[\s]*[\)]))*?$/m'; $str = ' [serie ] author, author - this is it (1234, publish ,ISBN-10: 345-801-028-x ) [serie ] author, author - this is it (1234, publish ,ISBN-10: 345-801-028-x ) [series ] author - this is it (1234, 345-801-028-8) [series ] author - this is it (1234, 345-801-028-x) [series ] author - this it (1234,ddddd 345-801-028-8) [series ] author - this is it (1234, 345-801-028-8) [series ] author - this is bad isbn becomes publisher (9234, 345-801-028-x) [series is messed up ]author - this is just date and isbn (1234, 978-801-028-060-7) [series ]author - this is just date and invalid isbn (1234, 978-801-028-060-x) [series ]author - this is invalid date (123, 1234erw978-8888801-028-060-7) [series ]author - this is isbn-13 (978-801-028-060-7) [series ]author - this is isbn-10 (78-801-0260-7) [series ]author - not enough dashes (78-80150260-7) [series ]author - this is it (12343-p978-801-0260-7) [series ]author - this is it (19,mix textandnumbers123,978-801-028-060-7) [series ]author - this is no date but valid isbn in pub name (1234-lk-jkj978-801-028-060-7) [series ]author - this is it (1234,lkjkj978-801-028-060-7) [series ]author - this is it (123,4lkjkj,978-801-028-060-7) [series ]author - this is it (1234,jhkh987\'&%\'%$#$%&ljh,lkjnkjnlkjhljh 5545t , 978-801-028-060-7) (,1234) [series gets messed up ]author - this is missing date but has comma (,ISBN-13: 978-801-028-060-7) [series ]author - this is it (1234,ISBN-10: 978-801-006-0) [series ]author - this is it (1234,ISBN-13: 978-801-028-060-7) [series ]author - this is it (,ISBN-10: 978-801-006-x) [series ]author - this is no date (ISBN-10: 978-801-006-x) [series ]author - this is dateonly (2020) '; 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