+ 1
Need help with python regular expression
I need a regular expression in python to find all the overlapping substrings in a string that start and end with a specific character For example: My String is : "aacbb" if start symbol is : 'a' and end symbol is : 'c' the output should be : ['aac','ac'] if start symbol is : 'a' and end symbol is : 'b' the output should be : ['aacbb','acbb','aacb','acb']
3 Answers
+ 2
"^acquot;
"^abquot;
You can use the caret symbol (^) at the start of a regex to indicate that a match must occur at the beginning of the searched text. Likewise, you can put a dollar sign ($) at the end of the regex to indicate the string must end with this regex pattern. And you can use the ^ and $ together to indicate that the entire string must match the regex
+ 1
Thanks for the reply mates,
Here is my code
import re
n=int(input())
string=input()
q=int(input())
for _ in range(q):
(x,y)=tuple(input().split(" "))
res=re.findall(f"(?=({x}.*{y}))",string)
print(len(res))
Input
5
aacbb
2
a c
a b
Output
2
2
Expected Correct Output
2
4
0
I hope that someone will help u,
Because I'm just a beginnerđ