0

I need to avoid capturing a match if it ends with a colon.

Example below:

item: something  
item: another  
item: things:  
item: yetanother  

My desired result is to return nothing from the 3rd line.

I feel like I'm close with this regex using negative lookahead:

item: (\w+)(?!:)  

But it's just cutting off the last letter, not avoiding the whole word.

The fourth bird
  • 154,723
  • 16
  • 55
  • 70
kaizen
  • 9
  • 2

1 Answers1

1

No need for lookarounds, just specify that the line should not end with a colon:

^.*[^:]$

https://regex101.com/r/oxBsMU/1

MonkeyZeus
  • 20,375
  • 4
  • 36
  • 77