regex - How to describe an optional negative lookahead in regular expression? -


i appointment description of calender entries program called khal outputs using grep. output of khal looks this:

20:30-22:30 13.05.2015: manfred treffen repeat: freq=weekly;byday=we;wkst=mo 09.05. - 12.05.2015: britt besuch 

in example match manfred treffen , britt besuch. however, can see first appointment repeating appointment , there khal adds these information output. in case regular expression has assure every whole part starting repeat: omitted, of course if exists.

grep -op "(?<=: )(.)+(?=repeat: .+$)" gets me manfred treffen not britt besuch

however grep -op "(?<=: )(.)+(?=repeat: .+$|$)" gives me descriptions of both appointments first 1 whole "repeat:…" part included.

what seem need optional lookahead. found similar question on stackoverflow didn't understand approach (greedy match) nor possible adopt case.

try 1

(?<=\d{4}:).+?(?=repeat|$) 

demo


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -