1

I'm trying to add a second parameter to a lua function using gsub, but I can't figure it out. Here's the function:

function ScrubHTML(htmlString)
    return string.gsub(htmlString, "<.->", "");
end

As of right now it's only set up to sub out the <, ., -, and > characters, but I need to add something for any non-breaking spaces, "%nbsp;", as well.

I'm sure it's obvious from the post, but I am not a developer/am VERY inexperienced. I'm just playing around with some code on a test machine I have and have been stumped by this. I have tried combining some regex patterns in the find string, but it doesn't appear to work.

Any help would be greatly appreciated.

  • [You may not want to do it by yourself.](https://stackoverflow.com/a/1732454/10953006). I suggest you to use an existing HTML parser library for that, such as [htmlparser](https://github.com/msva/lua-htmlparser). – Robert Dec 09 '21 at 05:22
  • 1
    `<.->` in Lua patterns matches any string between `<` and then leftmost `>` (as `.-` is basically a `.*?` regex pattern). If you mean you also want to match spaces, sorry, Lua patterns do not support alternation OR operator (like `|` in regex). – Wiktor Stribiżew Dec 09 '21 at 16:18
  • 1
    Does this answer your question? [Lua pattern matching vs. regular expressions](https://stackoverflow.com/questions/2693334/lua-pattern-matching-vs-regular-expressions) – Wiktor Stribiżew Dec 09 '21 at 16:34

0 Answers0