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

/
/
g

Test String

Code Generator

Generated Code

$re = '/\b(\w?)(\w?)(\w?)(\w?)(\w?)(\w)\S?\6\5\4\3\2\1\b/'; $str = 'tattarrattat – aibohphobia – a joke word meaning "fear of palindromes", deliberately constructed so as to be one (various other words have been contrived along these lines, such as ailihphilia, a love of palindromes, elihphile, a lover of palindromes, etc.) detartrated – past tense of “to detartrate”, a chemical term meaning to remove tartrates; alternatively an adjective indicating that tartrates have indeed been removed (this is the longest English palindrome in the Guinness Book of Records, though it is not listed in dictionaries; it is, however, encountered in some discussions of Concord grape juice [1]) kinnikinnik – variant (or common misspelling) of kinnikinnick, a Native American smoking mixture Aoxomoxoa – A 1969 album by the Grateful Dead. Malayalam – An Indian dialect (Mother tongue of Keralites). deleveled – past tense and past participle of "delevel", to demote or be demoted to a lower level. evitative – a grammatical case indicating fear or aversion. redivider – someone or something that redivides (tied for longest "real" palindrome that is not a proper noun and that appears in English dictionaries). releveler – (American spelling) someone or something that levels again (tied for longest "real" palindrome that is not a proper noun and that appears in English dictionaries). Rotavator – a type of machine for breaking up soil (trademark) Seven letters Adinida – a suborder of planktonic organisms deified – past tense of "to deify", meaning to consider as a god hadedah – a type of S. African grey ibis murdrum – in old English law, a secret killing Nauruan – the language spoken in Nauru peeweep – a type of bird, often understood to be a lapwing racecar – a racing car reifier – someone who reifies (considers an abstract concept to be real) repaper – to cover again with paper reviver – someone or something that revives or restores rotator – a thing that rotates seities – plural of seity, the essence of an individual sememes – plural of sememe, the interpretation given to a morpheme (a language unit) Senones – an ancient people who lived in part of what is now France soosoos – plural of soosoo, a type of dolphin degged - past tense of to deg, meaning to water a plant denned – past tense of to den, meaning to live in a den hallah – a variant of challah, a special Jewish braided bread eaten on Sabbath and Jewish holidays. mallam – in West Africa, a learned man marram – a type of grass pip-pip – an old-fashioned British word for good-bye pull-up or pullup – an exercise in which one pulls oneself up by the arms redder – more red renner – an archaic variant of runner revver – someone or something that revs (an engine) selles – plural of selle, an archaic word for a saddle sesses – plural or third-person present tense of sess, an archaic word for tax (a variant of assess) succus – any of various liquids excreted by animals or plants terret – a metal ring on a harness, through which the reins pass tirrit – according to Webster’s Dictionary (1913): "A word from the vocabulary of Mrs. Quickly, the hostess in Shakespeare’s Henry IV., probably meaning terror" tut-tut – a disapproving sound; to make such a sound solos – plural of solo stats – contraction of statistics stets – third-person present tense of "to stet", meaning to indicate that a passage of text should remain unchanged stots – third-person present tense of "to stot", meaning to leap or bounce sulus – plural of sulu, a type of sarong Susus – plural of Susu, a member of a West African people tenet – a belief or principle torot – see [2], [3] Wakaw - A town and a lake in Saskatchewan, Canada. Xanax - Pfizer\'s trade name for alprazolam, a benzodiazepene used to treat panic disorder (severe anxiety and panic attacks). Anna – a girl’s name Beeb – an informal name for the BBC boob – a blunder; a breast deed – various common meanings esse – existence or essence goog – an egg (Australian slang) immi – a Swiss unit of volume keek – to peep kook – a crazy person ma\'am – a contraction of madam otto – variant of attar, an essential oil Otto - a proper name peep – various common meanings poop – a raised deck at the stern of a ship; various other meanings sees – third-person present tense of ‘to see’ toot – the sound made by a\\ pip – a seed; also, to get the better of pop – a cola; also, to burst pup – the young of any of various mammals sis – shortened form of "sister" sos – plural of "so", the fifth tone of the diatonic scale in music tat – tattoo tet – the ninth letter of the Hebrew alphabet tit – a small bird (British); a br\\ zzz – the sound of snoring aa – lava having a rough surface (pron. a’a’) ee – an extinct Hawaiian bird (pron. e’e’) mm – used to express satisfaction'; 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