Using string.gmatch() to get <img> tags

I have an HTML file from which I need to get all the images links and put them in a table.

I’ve been trying out different snippets from an HTML parsing guide, but none seem to work.

images = {} text = getHTML() for i in string.gmatch(text, "\<%s\*img ([^\>]\*)\>") do images[#images+1] = i print(i) -- Is not printing anything, not even 'nil' end

Any ideas what I could be doing wrong? Workarounds?

your pattern doesn’t appear to have any syntax problems, but hard to tell if it would actually parse what you expect without seeing at least a snippet of the input text.

since you get NO prints, that means NO matches, so there’s something about your data and/or pattern that don’t agree.  but you haven’t yet shown us enough to guess what that might be.

 fe, what if they’re uppercase “<IMG” tags?  maybe need a string.lower() preprocess?  are you sure the images are even in the html and not generated by script?  are you sure there’s a literal space following “img” and not some other whitespace like tab?  etc

The site I was downloading the HTML from changed while I was working on the app and now the img URLs are generated by a script, just like you said. Thanks for the tip, now I just need to change the syntax and it should be working fine.

your pattern doesn’t appear to have any syntax problems, but hard to tell if it would actually parse what you expect without seeing at least a snippet of the input text.

since you get NO prints, that means NO matches, so there’s something about your data and/or pattern that don’t agree.  but you haven’t yet shown us enough to guess what that might be.

 fe, what if they’re uppercase “<IMG” tags?  maybe need a string.lower() preprocess?  are you sure the images are even in the html and not generated by script?  are you sure there’s a literal space following “img” and not some other whitespace like tab?  etc

The site I was downloading the HTML from changed while I was working on the app and now the img URLs are generated by a script, just like you said. Thanks for the tip, now I just need to change the syntax and it should be working fine.