You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
d matches the character d literally (case sensitive)
The grep command prints lines matching a pattern
The -P argument interprets PATTERN as a Perl regular expression
Color and colour are different spellings of the same word.
Color is the preferred spelling in American English, and colour is preferred in all other main varieties of English. The following regex matches both. "
'user@:~$' • grep -P 'colou?r' file
colo matches the characters colo literally (case sensitive)
u matches the character u literally (case sensitive)
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
r matches the characters r literally (case sensitive)
Match wh following by one, two or three e character: 'whe whee wheee'
'user@:~$' • grep -P 'whe{1,3}' file
The grep command prints lines matching a pattern
The -P argument interprets PATTERN as a Perl regular expression
whe matches the characters whe literally (case sensitive)
{1,3} matches the previous token between 1 and 3 times, as many times as possible, giving back as needed (greedy)
Match either gray or grey
'user@:~$' • grep -P '{gray|grey}' file
The grep command prints lines matching a pattern
The -P argument interprets PATTERN as a Perl regular expression
'{gray|grey}' must match gray or gray
Let's say you want to match a text like !abc! or !123!. Only these two are possible, and you want to capture the abc or 123.
'user@:~$' • grep -P '!(abc|123)!' file
The grep command prints lines matching a pattern
The -P argument interprets PATTERN as a Perl regular expression
'{gray|grey}' must match !abc! or !123!
Search /usr/share/dict/dutch for all words which end in 'vuur', without matching the word 'vuur' itself.
b matches the character b literally (case sensitive)
. matches any character (except for line terminators)
{2} matches the previous token exactly 2 times
l matches the character l literally (case sensitive)
$ asserts position at the end of a line
The perl command is how to execute the Perl interpreter
The -n argument causes Perl to assume the following loop around your program, which makes it iterate over filename arguments somewhat like sed -n or awk:
The -e argument may be used to enter one line of program.
aeiou matches a single character in the list aeiou (case sensitive)
{4,5} matches the previous token between 4 and 5 times, as many times as possible, giving back as needed (greedy)
Exercise 2:
Count the number of words out of the file /usr/share/dict/dutch which which start with 'ver', and end with 'en'. ('verplaatsen' is ok, 'overkomen' and 'vertrek' are not ok)
ver matches the characters ver literally (case sensitive)
. matches any character (except for line terminators)
'*' matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
$ asserts position at the end of a line
The wc command prints newline, word, and byte counts for each file
The -l argument prints the newline counts
Exercise 3:
In those annoying night television games people must guess words. Given are all the letters the word consist of and a list of dots, one for every letter.
E.g. We are looking for a 23 letter word with a 'v' in position 8: '.......v...............'. Use the letters 'enrtiscau' for the other positions."
. matches any character (except for line terminators)
{10} matches the previous token exactly 10 times
'*' matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\1 matches the same text as most recently matched by the 1st capturing group
Exercise 11:
To combat spam, a mail server administrator wants to reject mail coming from home users. The IP addresses home users always seem to connect from have hostnames like this: ip.domain. Create a regex which matches all these host names.