2

In Lua, in want to get captures from a string containing a specific substring. E.g. in the string

 test = "<item>foo</item>  <item>bar</item>"

I want to get items containing "a", which in this case would be "bar". I tried this:

print(string.find(test, "<item>(.-a.-)</item>"))

but the result is:

1   34  foo</item>  <item>bar

So .- is more greedy than I expected. What would be the correct pattern?

2
  • 1
    Do not parse XML with patterns. Commented Aug 30, 2013 at 8:00
  • This wasn't meant for parsing, I'm looking for specific parts in the XML. Commented Sep 1, 2013 at 8:16

1 Answer 1

1

Try print(string.find(test, "<item>([^<]-a.-)</item>")).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.