Created
October 20, 2016 21:48
-
-
Save jculvey/3718a47d64c9dfcaa942852297b8c9a2 to your computer and use it in GitHub Desktop.
Regex in a nutshell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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