+ 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']

9th May 2021, 6:28 AM
aval123
3 ответов
+ 2
"^ac
quot; "^ab
quot; 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
9th May 2021, 6:59 AM
Alaa Aldeen Shammr
Alaa Aldeen Shammr - avatar
+ 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
9th May 2021, 7:42 AM
aval123
0
I hope that someone will help u, Because I'm just a beginner😁
10th May 2021, 4:11 AM
Alaa Aldeen Shammr
Alaa Aldeen Shammr - avatar