-2

I'm trying to find the word: <*hasburnt*> in the string below using the this regex: <\*.*(bur).*\*>

But it gives me both <*hasburnt*> <*electrical*>. How do I just get <*hasburnt*> ?

bench testedstarter, starter just makes noise, and <*hasburnt*> <*electrical*> smell.

rsajdak
  • 93
  • 12

1 Answers1

2

Try this: /<.*?(bur).*?>/

Regex101 demo

The reason for ? here is because .* tries to match as much characters as possible, so it also matches <electrical. .*? makes it lazy - trying to match as little as possible, and as such ending the match at <hasburnt>.

EDIT: using ? for the first .* would make <hasburnt> independent of positions of similar strings.

Oleksii Filonenko
  • 1,551
  • 1
  • 17
  • 27