r'(^|^A)(\S+)(B$|$)'
results to matches everything, which actually equals to ^\S$.
How to write one matches “begins with A or ends with B, may both but not neither?”
PS: I also need refer to group (\S+) in the substring module.
Example:
Match Aanything, anythingB, and refer anything group in the replace.
Problem solved.
I use this regex in python, I found this in the Python manual:
So my final answer is:
Commands:
‘anything’
‘anything’
While
AanythingBgive meanythingBback, but I don’t care anyway.‘anythingB’