Regular expressions¶
[]¶
Square brackets define a list or range of characters to search for:
[abc]corresponds to a, b or c
[a-z]corresponds to any lower case letter
[A-Za-z]corresponds to each letter
[A-Za-z0-9]corresponds to any letter or digit
Number¶
.corresponds to a single character
*corresponds to zero or more times the preceding element, for example
colou*rmatchescolor,colour,colouuretc.?corresponds to zero or once the preceding element.
colou?rmatchescolorandcolour.+matches the previous element one or more times, for example
.+matches.,..,...etc.{N}corresponds
Ntimes to the preceding element.{N,}matches the previous element
Nor more times.{N,M}corresponds at least
Ntimes to the preceding element, but not more thanMtimes.
Position¶
^puts the position at the beginning of the line.
$puts the position at the end of the line.
Link¶
|means or.
Escape characters and literals¶
\is used to search for a special character, for example to find
.orgyou have to use the regular expression\.orgbecause.is the special character that matches every character.[\b]Backspace character
\dmatches every single digit.
\Dmatches any non-digit.
\wmatches any part of a word character and is equivalent to
[A-Za-z0-9].\Wmatches any non-word character.
\smatches any space, tab or newline.
\Smatches any non-whitespace character.
\AStart of a string.
\ZEnd of a string.
\bmatches a pattern on a word boundary.
\Bmatches any non-word boundary.