Python makes regular expressions available through the **re module**.

For the first part in using regular expressions and matching the string

you can visit this link –> Matching the beginning of a string (Regex) Regular Expressions in python

The re.search() method **takes a regular expression pattern and a string and searches for that pattern within the string**. If the search is successful, search() returns a match object or None otherwise.

pattern = r"(your base)" sentence = "All your base are belong to us." match = re.search(pattern, sentence) print(match.group(1)) # Output: 'your base' match = re.search(r"(belong.*)", sentence) print(match.group(1)) # Output: 'belong to us.'

**OUTPUT:**

your base

belong to us

**ILLUSTRATION EXAMPLE** (using the command line)

Searching is done anywhere in the string unlike re.match . You can also use re.findall .

You can also search at the beginning of the string (use ^ ),

match = re.search(r"123$", "zzb123") match.group(0) # Out: '123' match = re.search(r"123$", "123zzb") match is None # Out: True

or both (use both ^ and $ ):

match = re.search(r"^123$", "123") match.group(0) # Out: '123'

**ILLUSTRATION:** refer the code below

**Morae Q!**

- Find the number of strings made by using each alphabet as starting character.
- Find the Pythagorean triplet.
- Find out what is the minimum possible energy he needs to spend.
- Sort the array in non-decreasing order and print out the original indices of sorted array.
- Compute the number of landmasses on the planet after all the meteorites have fallen.
- Give the appropriate server status as output.
- Regular expressions (Regex) using search module in python.
- Find the minimum distance between any pair of equal elements in the array.
- Find the total number of matching pairs of socks that are available.
- Find the total number of teams which can work together and cannot work together.
- Given the heights of all the boys and girls tell whether it is possible for all boys to get a girl.
- Find the sequence of cities to visit according to coordinates and conditions.
- Find the number of unique patches of rectangular land to grow samba(rice) in.
- Regular expression Regex matching strings.
- Generate a greeting quote for admin.
- Find all the cavities on the map and replace their depths with the character X.
- Check whether the given graph is Bipartite or not.
- Find the status of the passengers and safari cars at zoo after k units of time.
- Determine the chair number occupied by the child who will receive that chocolate.
- Check if Rubik’s cube of any dimensions can be assembled.