Gen-AI Developer Classroom notes 15/Mar/2025

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

  1. email id
  2. url
  3. domain name
  4. us phone numbers
  5. 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

Sequences

  • Common methods of sequences

Python Generator

Python List Comprehensions

By continuous learner

enthusiastic technology learner

Leave a Reply

Discover more from Direct AI Powered By Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading