Given a string, the task is to check if that string contains any g followed by one or more e’s in it, otherwise, print No match.
Input : geeks for geeks Output : geeks geeks Input : graphic era Output : No match
Approach : Firstly, make a regular expression (regex) object that matches a word which contains ‘g’ followed by one or more e’s, then pass a string in the
findall method. This method returns the list of the matched strings. Loop through the list and print each matched word.
\w – represent Any letter, numeric digit, or the underscore character.
* means zero or more occurrence of the character.
+ means one or more occurrence of the character.
Below is the implementation :
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Python regex to find sequences of one upper case letter followed by lower case letters
- Python | Check if string matches regex list
- Python program to read file word by word
- Python program to Count Uppercase, Lowercase, special character and numeric values using Regex
- Python program to find files having a particular extension using RegEx
- Python | Find all close matches of input string from a list
- Python | Check if suffix matches with any string in given list
- Python - Extract Indices of substring matches
- Python Regex - Program to accept string starting with vowel
- Python Regex | Program to accept string ending with alphanumeric character
- Find all the patterns of “1(0+)1” in a given string using Python Regex
- The most occurring number in a string using Regex in python
- Name validation using IGNORECASE in Python Regex
- Python | Swap Name and Date using Group Capturing in Regex
- Python - Substituting patterns in text using regex
- Categorize Password as Strong or Weak using Regex in Python
- How to check if a string starts with a substring using regex in Python?
- Parsing and Processing URL using Python - Regex
- Python - Check if String Contain Only Defined Characters using Regex
- Converting a 10 digit phone number to US format using Regex in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : ManasChhabra2