Skip to content

Instantly share code, notes, and snippets.

@jculvey
Created October 20, 2016 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jculvey/3718a47d64c9dfcaa942852297b8c9a2 to your computer and use it in GitHub Desktop.
Save jculvey/3718a47d64c9dfcaa942852297b8c9a2 to your computer and use it in GitHub Desktop.
Regex in a nutshell
# egrep -i '^q[u]' testfile
# egrep -i '^q[^u]' testfile
quarter
qatre
A quarter mile.
# egrep -i '3[-./]19[-./]12' testfile
3/19/12
3-19-12
3.19.12
# egrep -i '^(From|Subject|Date):' testfile --color
From: Bob
Subject: Hello
Date: today
# egrep -i 'ello\>' testfile
shello
trello
fellow
mellow
# egrep -i 'July? (4(th)?|fourth)' testfile
July 4th
Jul 4th
Jul fourth
July 4 1966
# egrep -i '<hr( +size *= *"?.*"?)? */?>' testfile
<h1>
<h2>
</h2>
<h3 >
<h3 id="foo">
<hr>
<hr />
<hr size=12 >
<hr size="12px">
# Backreferences
# The following finds double words
# egrep -i '\<([a-z]+)\> +\1\>' testfile --color
This is the the way
To the theatre.
# egrep -i '\<([0-9]+)?(\.)?([0-9]+)?f?\>' testfile --color
10
10.0
10.12
10.
.12
.10f
$.10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment