regularpython@gmail.com
Regular Expressions
Regular expressions are the most important topic in python. These are used to find a string or character or digits in the given Data. In Web scraping and Django, this is the most powerful topic. I have a lot of web scraping and website development projects. I will explain the real power of Regular Expressions. Python provides re module for regular expressions. It has three most powerful functions,
1.Match
2.Search
3.Search and Replace
Characters |
Description |
Details |
. |
It finds all characters except a newline character |
Click here for more details |
\d |
It finds all digits 0-9 |
Click here for more details |
\D |
It finds all characters except digits |
Click here for more details |
\s |
It finds all white space characters Space, tab, return |
Click here for more details |
\S |
It finds all characters except white space characters |
Click here for more details |
\w |
It finds all word characters like a-z, A-Z, 0-9, _ |
Click here for more details |
\W |
It finds all characters except word characters |
Click here for more details |
\b |
It matches boundaries |
Click here for more details |
\B |
It matches non-boundaries |
Click here for more details |
^ |
Matches beginning of the line |
Click here for more details |
$ |
Matches ending of the line |
Click here for more details |
[…] |
It used to match a group of characters |
Click here for more details |
[^…] |
It used to match a group of characters not mentioned in square brackets |
Click here for more details |
* |
It matches 0 or more occurrences of the preceding expression. |
Click here for more details |
+ |
It matches 1 or more occurrences of the preceding expression. |
Click here for more details |
? |
It matches 0 or one occurrences of the preceding expression. |
Click here for more details |
{x} |
It matches exactly x number of occurrences of the preceding expression |
Click here for more details |
{a,} |
It used to match x or number of occurrences of the preceding expression |
Click here for more details |
{a, b} |
It is used to match the range |
Click here for more details |
a|b |
It is used to match a or b |
Click here for more details |
() |
It is used to make groups |
Click here for more details |
<.*> |
Greedy repetition matches |
Click here for more details |
<.*?> |
Non-greedy repetition matches |
Click here for more details |