Regular Expressions Make My Brain Hurt 0
If they also make your brain hurt, here’s a good tutorial.
If you are not sure what Regular Expressions (often called “regex”) are, they are a versatile tool for searching text for specific strings. You can search for strings with various permutations and qualifications.
Here’s an example, illustrating a search of the file /usr/doc/HTML/en/common/gpl-license for the any occurrence of a string including two characters followed by the characters “cept” (the -i means “ignore case”). The working directory was /usr/doc/HTML/en/common/, which is where the GNU Public License resides in Slackware –Current.
The text is choppy because the output of the command displays individual lines from the text file, rather than sentences:
$ grep -i "..cept" gpl-license
License. (Exception: if the Program itself is interactive but
special exception, the source code distributed need not include except as expressly provided under this License. Any attempt
5. You are not required to accept this License, since you have not
prohibited by law if you do not accept this License. Therefore, by
Program), you indicate your acceptance of this License to do so, and
make exceptions for this. Our decision will be guided by the two goals
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
Here’s some more searches I did during the tutorial:
grep "^[A-Z].*\.$" gpl-license <--Searches for all lines starting with capital letters or ending with periods.
egrep "(public license)" gpl-license <--Searches for all lines including the string "public license."
grep "^[A-Z]" gpl-license <--searches for all lines starting with capital letters.
These are very simple regex searches.
Here’s a complex regular expression string that I grabbed from a website. Note that it is just the search string, not prefaced by a search command:
\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b
When I understand that, I will consider that I have achieved geekdom.
Yes, this is my idea of fun.