use of \A in regular expression in python by R4R Team

A : In regular expression in python, It returns a match if the specified characters are at the beginning of the string.

Example-

re.search('AStart',"Start string") will match the pattern.
re.search('AEnd',"Start string") will not match the pattern.


program-

#import the re module
import re

#take input of string
print("Enter string")
s=input()

#check string is start with 'This'
x=re.search('AThis',s)
if x:
print("String is start with This")
else:
print("String is not start with This")


#check string is start with The
x=re.search('AThe',s)
if x:
print("String is start with The")
else:
print("String is not start with The")


output-

Enter string
This is programming
String is start with This
String is not start with The

Enter string
The program
String is not start with This
String is start with The


-In this program, we take a input of string, and check that the string is starts with 'This' or not, and in other part we check string is starts with 'The' or not.
Because of the 'A', we only focus on the starting thing of the string, and whatever in the ending in the string are not reflect on the match pattern.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!