简体   繁体   English

用正则表达式检测字符串的第一个匹配结尾的问题

[英]issue to detect first matching end of string with regex

I try to find the string starting with "start" and ending with one of this strings: (, |. | finish) with skipping "finish" when its followed by a "not" or "here".我试图找到以“start”开头并以以下字符串之一结尾的字符串:(, |. | finish) 后跟“not”或“here”时跳过“finish”。

Here is the example:这是示例:

CONF: For this charaxter start 6 years of  this Revision 01 its indicated in the house warranty  not finish for  received days  completion. affected you. of your face

for this i used the following regex:为此,我使用了以下正则表达式:

(start|START).*(?!not finish|here)(?=[.]|[,]|finish)

link for my try: https://regex101.com/r/USaH6I/1我的尝试链接: https://regex101.com/r/USaH6I/1

requested return is:要求的回报是:

start 6 years of  this Revision 01 its indicated in the house warranty  not finish for  received days completion

but I got:但我得到了:

start 6 years of  this Revision 01 its indicated in the house warranty  not finish for  received days completion, affected you

If you meant skipping matching if 'here' or 'not' is found after 'finish' then try this: (?:start|START).*?(?=[.]|[,]|(finish (?!here|not)))如果您的意思是在“完成”之后找到“这里”或“不”时跳过匹配,请尝试以下操作:( (?:start|START).*?(?=[.]|[,]|(finish (?!here|not)))

Test here: https://regex101.com/r/PaXBKL/1在这里测试: https://regex101.com/r/PaXBKL/1

If you meant skipping matching if 'here' or 'not' is found before 'finish' then try this: (?:start|START).*?(?=[.]|[,]|((?<!here|not) finish))如果你的意思是如果在 'finish' 之前找到 'here' 或 'not' 则跳过匹配,那么试试这个: (?:start|START).*?(?=[.]|[,]|((?<!here|not) finish))

These follow your condition of stopping when, or.这些遵循您停止时或时的条件。 is found.被发现。

Cases:案例:

When 'finish' is found first:当首先找到“完成”时:

CONF: For this charaxter start 6 years of this Revision 01 its indicated in the house warranty not finish for received days finish here completion. CONF:对于此版本 01 的此字符开始 6 年,其在房屋保修中表示在收到的天数内未完成,在此完成。 affected you.影响了你。 of your face你的脸

When 'finish' if followed by 'here'/'not' it will skip till a , or .当“完成”后跟“此处”/“不”时,它将跳到 a , or . is found:发现:

CONF: For this charaxter start 6 years of this Revision 01 its indicated in the house warranty not for received days finish here completion . CONF:对于此字符,此版本 01 开始 6 年,其在房屋保修中注明不是收到的天数,在这里完成 affected you.影响了你。 of your face你的脸

CONF: For this charaxter start 6 years of this Revision 01 its indicated in the house warranty finish not for , received days here completion. CONF:对于此版本 01 的 6 年开始的这个角色,其在房屋保修完成时表示不是,收到天数在这里完成。 affected you.影响了你。 of your face你的脸

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM