假设我有以下类似的文字:
_startOneEnd
_startTwoEnd
_startThreeEnd
我想匹配:以_start开头, 以End结尾 ,我想捕获中间的位,例如,上面变量中的一、二、三:
谁能建议一个正则表达式来捕捉这个?
假设我有以下类似的文字:
_startOneEnd
_startTwoEnd
_startThreeEnd
我想匹配:以_start开头, 以End结尾 ,我想捕获中间的位,例如,上面变量中的一、二、三:
谁能建议一个正则表达式来捕捉这个?
如果每一行输入只包含与您的示例类似的文本,则应该这样:
/^_start(.*)End$/
将^
模式锚定到字符串的开头。将其$
锚定到字符串的末尾。括号捕获中间部分。
It isn't clear if the part in the middle may only be the examples given.
If so, use this:
_start((One)|(Two)|(Three))End
If not, is it can be anything, try this:
_start(.*?)End
Note that the match is non-greedy.
在C#
中,您可以使用:
(?<=_start).*(?=End)