Before, you could describe the set of all digits using [0-9]. Because some sets are used regularly, there are short notations for them.
- \d is the set of add digits.
-
\s is the set of all spaces, e.g. or the line
break. - . matches all characters except the line break. .* can be used if you do not care about some content.
- \w is for letters in words. \w is the same as [0-9a-zA-Z]_.
- \\ matches the backslash \.
The following text is from "The Twelve Days of Christmas" by Harry Belafonte [source]. Here, animals are counted. Find all lines in which a number is followed by space followed by a word.
- On the 5th day of Christmas
- my true love sent to me
- 5 golden rings
- 4 calling birds
- 3 French hens
- 2 turle doves
- and a partridge in a pear tree.