Posted in Information Technology

Regex Overview Examples

Usage in different languages

As the actual use of regular expressions is quite language specific there are separate cheat sheets:

Standards

Regex Variants

Variant Used By Meta Characters Back References
POSIX BRE grep, sed ^ $ \{\} \[\] \(\) . * GNU extension: \+ \? \1 … \9
POSIX ERE egrep, awk, gawk ^ $ {} [] () . * + ? | gawk: \\1 .. \\9
Perl RE Perl, C, PHP, Python, Ruby… Every programming language using PCRE ^ $ {} () . * + ? | Based on language

Perl \g1 \g2 … \g-1 \g-2 … \g{-1} \g{-2} … \g{name} \k{name} \g’name’ \k’name’
PHP \\1 .. \\9 $1 .. $99 ${1} .. ${99}
Python \1 .. \99 \g1 .. \g99 \g (?P…) (?P=name)

Other Hints:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s