Regular Expressions for Text Searching
- Refer Here for the Programiz Docs and also Refer Here to This article for Tables with meanings of meta characters
Find regular expressions for
- email id
- url
- domain name
- us phone numbers
- indian phone numbers
Python re methods
Here is a table summarizing the key methods of the re module in Python’s standard library, along with a brief description of what each method does:
| Method | Description |
|——–|————-|
| re.compile(pattern) | Compiles a regular expression pattern into a regular expression object, which can be used for matching using its methods like search(), match(), findall(), etc. |
| re.search(pattern, string) | Searches for the first occurrence of the pattern in the string and returns a match object if found; otherwise, returns None. |
| re.match(pattern, string) | Attempts to match the pattern at the beginning of the string. Returns a match object if successful; otherwise, returns None. |
| re.fullmatch(pattern, string) | Attempts to match the entire string against the pattern. Returns a match object if successful; otherwise, returns None. |
| re.findall(pattern, string) | Finds all non-overlapping matches of the pattern in the string and returns them as a list of strings. |
| re.finditer(pattern, string) | Finds all non-overlapping matches of the pattern in the string and returns an iterator yielding match objects. |
| re.split(pattern, string) | Splits the string into substrings using the pattern as a delimiter and returns a list of these substrings. |
| re.sub(pattern, repl, string) | Replaces occurrences of the pattern in the string with the replacement string and returns the modified string. |
Lets Play with regex
- Python has a standard library module called as
re. - Refer Here for some of the examples done
- Exercise:
- Write python functions to find
- if the password is strong or not
- if the url is valid or not
- Write python functions to find
Sequences
- Common methods of sequences
Python Generator
- Refer Here for example
Python List Comprehensions
-
Refer Here for list comprehension guide
-
Refer Here for the sample done
