简体   繁体   中英

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".

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

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)))

Test here: 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))

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. affected you. of your face

When 'finish' if followed by 'here'/'not' it will skip till 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 . 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. affected you. of your face

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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