Perl Regex


Long-Term Learning

Learn efficiently and remember over time.

Start Long-Term Learning

Get personalized study reminders at intervals optimized for better retention.
Track your progress on this set by creating a folder
Or add to an existing folder

Add this set to a folder

  • Regex Enclosed in Slashes

    /search term/

    Binding Operator


    Negative Binding Operator


    Override Case Sensitivity

    -i or /i /searchterm/i

    Pattern Matching

    /m/searchterm/ same as /searchterm/

    Prevent Interpolation of Special Characters


    Anchor - Search Beginning of the string

    ^ Example /^The/

    Anchor - Search End of the String

    $ Example: /searchterm\.$/

    Any Character in a search

    /h[aiou]t/ hat, hit, hot, or hut

    Does not include

    /wa[^rx]/ Does not contain war or wax

    Character set range

    [0-9] [a-z] [A-Z] [0-9a-z]

    Character Range \d and \D

    [0-9] and [^0-9]

    Character Range \w and \W

    [0-9A-Za-z_] and [^0-9A-Za-z]

    Character Range \s and \S

    [\ \t\n\r] (space,tab,newline,return)

    Character Range \b and \B

    Boundaries between words

    Character Range .

    Match Any Character

    Character Class [[:alpha:]]

    Alphabetic Characters

    Character Class [[:alnum:]]

    Alphabetic or Numeric Characters

    Character Class [[:digit:]]

    Digits 0 to 9

    Character Class [[:lower:]]

    Lowercase Letters

    Character Class [[:upper:]]

    Uppercase Letters

    Character Class [[:punct:]]

    Punctuation Characters

    Alternative Operator

    /red|blue/ or /(red)|(blue)/ or /(red|blue)/

    Quantifiers: Optional character

    ? /g?reed/ - Search for greed or reed (? is after)

    Quantifiers: May occur more than one time

    + /n+/ - Searches for n, or nn, or nnn....

    Quantifiers: May occur once, numerous times, or none

    /trees/ - Searches for tree, trees, or treess ...

    Quantifiers: Number of Instances

    {,} /\w{5}/ - Five letter word, {4,} 4 or more {3,7} 3-7 instances

    Greedy: Find the first match that occurs

    ? - "this and thus" /th.?s/ matches "this" /th.*s/ would match "this and thus" (to the last 's')

    Greedy: Find a match using as few repeats as possible, but to allow at least one repeat


    Greedy: Find a match using zero repeats if possible


    Backreferences - Results of a search

    Outside Regex :$1, $2, etc. - In Regex: \1 and \2

    Substitution Operator

    =~ s/old/new/; (Replaces old with new; first instance only)

    Global Replacement

    =~ s/old/new/g (The g at the end is for all instances)

    Modifiers: Allow string to behave like a set of multiple lines separated by the newline character


    Modifiers: Ignore newline characters and the search string is treated as a single line

    s - For example '.' will now match any character, even newline characters.

    Modifiers: Replace only the last match, used with g


    Modifier: Ignore whitespace and allow comments


    Transliteration: Replace each character

    =~ tr/abc/xyz/; Replaces all 'a' with 'x', all 'b' with 'y', etc.

    Transliteration: Delete extra characters

    =~ tr/ABC/ab/d; - Replace 'A' with 'a', 'B' with 'b', deletes 'C' (Without d, 'C' with 'b')

    Substitution / Transliteration Additional Delimiters

    We can use [] or <>; easier if searching for /

    Substitution / Transliteration Create Delimiters

    =~ m#searchterm#

    Search for a Delimiter, and create substrings

    split / /,$colors ($colors="r g b"; @colors=split...)

    Create string from substring

    join " ",@colors (@colors="red green blue";$colors=join...)

    Inline Comments in searches

    =~ /searchterm(?#Comment)/

    Using inline modifiers in Regex

    =~ /(?i)searchterm/ (Same as /searchterm/i)

    Regex without backreferences

    ?: - /(?:abc)?.*(def)/ - $1 will be the result from (def) not (abc)


    ?= Example: =~/one (?=two)/



    Negative Lookahead


    Negative Lookbehind


    Please allow access to your computer’s microphone to use Voice Recording.

    Having trouble? Click here for help.

    We can’t access your microphone!

    Click the icon above to update your browser permissions above and try again


    Reload the page to try again!


    Press Cmd-0 to reset your zoom

    Press Ctrl-0 to reset your zoom

    It looks like your browser might be zoomed in or out. Your browser needs to be zoomed to a normal size to record audio.

    Please upgrade Flash or install Chrome
    to use Voice Recording.

    For more help, see our troubleshooting page.

    Your microphone is muted

    For help fixing this issue, see this FAQ.

    Star this term

    You can study starred terms together

    NEW! Voice Recording

    This is a Plus feature