-1

I'd like to match if x > 64 then return 0, 0 end inside this string.

 function if x > 64 then return 0, 0 end return 1, 0 end

I'm using if(.*)then(.*)end. However, this matches: if x > 64 then return 0, 0 end return 1, 0 end, which is one end too many.

Lucien
  • 776
  • 3
  • 12
  • 40

1 Answers1

0

This should do:

if(.*)then(.*?)end

You could add word boundaries to make sure you match end as a word, not as a part of a variable name:

if(.*)then(.*?)\bend\b

To analyse code, you probably should use a parser instead of a regex, though.

Eric Duminil
  • 52,989
  • 9
  • 71
  • 124