- Write a Python program that matches a string that has an a followed by zero or more b's
import re str_check=raw_input("Enter a string") match=re.search(r'ab*',str_check) if match: print("Matched string is",match.group()) else: print("string didn't match")
Enter a string abby ('Matched string is', 'abb') Enter a string a ('Matched string is', 'a') Enter a string b string didn't match
- Write a Python program that matches a string that has an a followed by one or more b's
import re str_check=raw_input("Enter a string") match=re.search(r'ab+',str_check) if match: print("Matched string is",match.group()) else: print("string didn't match")
Enter a string abby ('Matched string is', 'abb') Enter a string a string did'nt match Enter a string b string didn't match
- Write a Python program that matches a string that has an a followed by zero or one 'b'
import re str_check=raw_input("Enter a string") match=re.search(r'ab?',str_check) if match: print("Matched string is",match.group()) else: print("string didn't match")
Enter a string abbbbby ('Matched string is', 'ab') Enter a string a ('Matched string is', 'a') Enter a string b string didn't match
- Write a Python program that matches a string that has an a followed by three 'b'.
import re str_check=raw_input("Enter a string") match=re.search(r'ab{3}',str_check) if match: print("Matched string is",match.group()) else: print("string didn't match")
Enter a string abbbby ('Matched string is', 'abbb') Enter a string abb string did'nt match Enter a string bbb string didn't match
- Write a Python program that matches a string that has an a followed by two to three 'b'
import re str_check=raw_input("Enter a string") match=re.search(r'ab{2,3}',str_check) if match: print("Matched string is",match.group()) else: print("string didn't match")
Enter a string abby ('Matched string is', 'abb') Enter a string abbbbby ('Matched string is', 'abbb') Enter a string ab string didn't match
- Write a Python program to find sequences of lowercase letters joined with a underscore
import re str_check=raw_input("Enter a string") match=re.search(r'[a-z]+_[a-z]+',str_check) if match: print("Matched string is",match.group()) else: print("string didn't match")
Enter a string alex_lion ('Matched string is', 'alex_lion') Enter a string abbbbby string didn't match
- Write a Python program to find sequences of one upper case letter followed by lower case letters
import re str_check=raw_input("Enter a string") match=re.search(r'[A-Z]{1}[a-z]+',str_check) if match: print("Matched string is",match.group()) else: print("string didn't match")
Enter a string Alex_lion ('Matched string is', 'Alex') Enter a string alexTheLion ('Matched string is', 'The')
- Write a Python program that matches a string that has an 'a' followed by anything, ending in 'b'
import re str_check=raw_input("Enter a string") match=re.search(r'a.+b$',str_check) if match: print("Matched string is",match.group()) else: print("string didn't match")
Enter a string theappleb ('Matched string is', 'appleb') Enter a string ab string didn't match
- Write a Python program that matches a word containing 'z', not start or end of the word
Tuesday 8 December 2020
Regular Expression Exercise in python
Subscribe to:
Post Comments (Atom)
list operations in python
How to make each term of an array repeat, with the same terms grouped together? i/p: [A,B,C] o/p: [A,A,A,B,B,B,C,C,C] Solution: >...
-
In the Gregorian calendar three criteria must be taken into account to identify leap years: The year can be evenly divided by 4, is a le...
-
How to make each term of an array repeat, with the same terms grouped together? i/p: [A,B,C] o/p: [A,A,A,B,B,B,C,C,C] Solution: >...
-
Guido Van Rossum: A Dutch programmer, popularly known as the author of Python programming language. He has created Python in 1989 an...
No comments:
Post a Comment