A regular expression that matches the part between An and B. if there is no B, take the part after A.

talk about the effect first:
A VV BCCC matches VV
A CCCCCD matches CCCCCD

I will
the first

if I implement it alone.
-sharp -*- coding: utf-8 -*-
import re
-sharp
str = "AVVBCCC"
forword = re.search(r"A(.*)B", str).group(1)
print(forword)

the second type

-sharp -*- coding: utf-8 -*-
import re
-sharp
str = "ACCCCCD"
forword = re.search(r"A(.*)", str).group(1)
print(forword)

could you tell me how to write it together?


first judge whether there is B in the string. For the first type of string that does not need to be obtained in the last step for the second type


, you can intercept the string directly


'A ([^ B] +)'


(?<=A)[^B]+
.
Menu