1

I wrote some code like this:

        local word = "<color=#FF0000>123</color>asdf<color=#00FF00>456</color>"
        local list = {}
        for match in string.gmatch(word, "<color=#%w+>.+</color>") do
            print(match)
        end

But the output was the total word "<color=#FF0000>123<//color>asdf<color=#00FF00>456<//color>",

But what I want is "<color=#FF0000>123<//color>" and "<color=#00FF00>456<//color>",

How can I get the matches I want?

link
  • 25
  • 4
  • @TimBiegeleisen that doesn't work in Lua. `?` may only be used for single optional characters in patterns. Lua patterns aren't RegEx. The "lazy" quantifier is `-`. – Luatic Apr 20 '22 at 09:25
  • You should [not parse HTML with RegEx (or patterns)](https://stackoverflow.com/a/1732454/7185318) – Luatic Apr 20 '22 at 10:05

1 Answers1

1

Change .+ to .-.

+ find longest sequence. - find shortest sequence.

Reinisdm
  • 126
  • 3