当前位置: 动力学知识库 > 问答 > 编程问答 >

Delete the begin and the end with regex

问题描述:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: