问题描述:

Here is my phrase : "Begin xxxxxxxxx The End"

With

re(r'Begin\s*(.*)')

i can delete the word "Begin"

But in the same time how to delete "The End"

网友答案:

Try this one,

(?i)(^Begin|The\sEnd$)

just remove (?i) if you want case sensitive.

网友答案:

Just add more after your .*. A question mark will minimize the match so you don't pick up the surrounding spaces.

r'Begin\s*(.*?)\s*The End'

Note that you're not actually deleting anything; you're returning the text in the middle.

相关阅读:
Top