Add-On REGEX Flashcards
Show an example of the following anchors?
- Beginning of a string
- End of a string
- Word boundary
‘^SearchString’
‘SearchString$’
‘\bSearchString\b’
What are character classes for:
any lowercase letter
any uppercase letter
any letter
hexadecimal values
[[:lower:]]
[[:upper:]]
[[:alpha:]]
[[:alnum:]]
Regex example to check if only one char was entered?
’^[[:alpha:]]$’
Write a pattern that matches any word that begins with b, followed by a vowel, and ending with t.
\bb[aeiou]t\b
Match any digit or carat symbol
Match line that does not contain numbers
Match any line containing a digit
Match any line containing a minus, zero or nine
[0-9^]
[^0-9]
[0-9]
[-09]
What are the special character classes for:
[0-9] (digits)
[\t\r\n] (whitespaces)
[A-Za-z0-9_]
[[:digit:]]
[[:space:]]
[[:alnum:]]
Regex should check only one of the following words item0, item1….
^item[[:digit:]]$
Find any three character?
‘\b[[:alnum:]]\b’
Find any line that contains only one character?
’^[[:alnum:]]$’
Match any word that contains three lowercase letters?
‘\b[[:lower:]]{3}\b’
5 ‘a’ characters
5 or more ‘a’ characters
between 5 and 7 ‘a’ characters
between 3 and 5 lowercase characters
a{5}
a{5,}
a{5,7}
[[:lower:]]{3,5}
What is the shorthand version of:
a{0,} - zero ore more
a{1,} - one or more
a{0,1} - zero or one
a*
a+
a?
Find any number, whether it’s a whole number or a decimal
’[[:digit:]]+.?[[:digit:]]*’
Search for dog or cat or fish
dog|cat|fish
Search for cat or bat?
cat|bat
[cb]at
Search for:
hack, crack, hacking, hacked, cracking, cracked
(hack|crack)(ing|ed)?
egrep command to search for IP address?
egrep ‘^([[:digit:]]{1,3}.){3}[[:digit:]]{1,3}$’ testgr.txt
egrep command that matches either 202-224-1228 or (202)224-1228?
egrep ‘(([[:digit:]]{3}))|([[:digit]]{3}-)[[:digit:]]{3}-[[:digit]]{4}’ testgr.txt
egrep command that matches either “color” or “colour”?
egrep ‘colo[u]?r’ testgr.txt
How can I do the following:
- Reverse grep
- Case insensitive
- show a byte offset in the input file to the match
- show only the match
- Color the exact match
- grep -v
- grep -i
- grep -b
- grep -o
- grep –color