https://www.youtube.com/watch?v=sa-TUpSx1JA
Meta Characters
Meta Character | Meaning of the meta character when searching |
. (dot) | any character except new line |
\d | any digit: 0-9 |
\D | not a digit(0-9) |
\w | any word character: a-z, A-Z,0-9, _ |
\W | not word character |
\s | whitespace: space, tab, newline |
\S | not whitespace |
Anchors: don’t match character but match invisible position before/after character. anchors will be used in conjuction with meta characters
Anchor | Meaning of the anchor when searching |
\b | Word boundary(eg start of a line, space) |
\B | not a word boundary |
^ | Beginning of the string |
$ | End of the string |
Matchers:
matcher | Meaning of the anchor when searching |
[ ] | Matches characters in bracket |
[^ ] | Match characters NOT in the bracket |
| | Either Or |
() | group |
Quantifiers:
Quantifier | Meaning of the quantifier when searching |
* | 0 or more |
+ | 1 or more |
? | 0 or one |
{3} | exact match |
{3,4} | range of numbers (minimum, maximum) |
RegEx in Python
Why use raws(r”string”) string while using regex. by default, python considers \t,\n as tab and newline. We want to use the raw string so that python doesn’t give special treatment to \n,\t etc.
print("\ttab")
tab
print(r"\ttab")
\ttab