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]+
.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e9bcb5-188b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e9bcb5-188b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?