Pattern matching help.

Regular expressions have never been something I would call a strength and Lua’s pattern matching is even harder for me to figure it out (though it’s probably simpler).

Anyway, I have a string of text that may contain an anchor tag and URL:
blah blah blah [text]Some Text[/text] blah blah blah.

I want to remove the link, leaving the text.

Here is the code I’m trying to use:

[lua]storyBody = story.content_encoded:gsub("(%w+)", “%1”)[/lua]

It is not stripping the text.

Any help on the right pattern to find [text]XXXXX[/text] and leave me XXXX?
[import]uid: 19626 topic_id: 15001 reply_id: 315001[/import]

Wow, must be really some censored content, it has an extra x after xxx :wink:

On the serious side,
Why are you using gsub? gsub is for substitution or replacing portions, and it requires a pattern and the replacement, however what you need is gmatch to obtain the string. Just wait for my next update, I’ll give you something to work with.

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 15001 reply_id: 55387[/import]

Yea, its some seriously erotic text :stuck_out_tongue:

I’m using gsub because I want to remove the link, but leave the text that the link wraps, in other words:

substitute:

[text]Click Here[/text]

with

[text]Click Here[/text]

I suppose I could do that with .find and then some substring operations, but substitute seems like the route to go. [import]uid: 19626 topic_id: 15001 reply_id: 55390[/import]

Try this,

stringy = "[test](http://www.oz-apps.com/page/1.html)" for k, v in string.gmatch(stringy, "%S\*") do print(k) end [import]uid: 3826 topic_id: 15001 reply_id: 55391[/import]

This regex will match anything between > and <

\>(.\*?)\<  

As long as your input text is in the format you listed, always, you should be able to grab it using that.

If you find it grabs the > and < you could loop through the result and rebuild it minus the first and last member of the result.
[import]uid: 5317 topic_id: 15001 reply_id: 55437[/import]

Remember that this site is your best friend when testing out regex expressions:

http://myregexp.com/signedJar.html

[import]uid: 5317 topic_id: 15001 reply_id: 55438[/import]

Actually this will probably work for me:

[lua]stringy = “blah blah blah test blah blah blah "
stringz = stringy:gsub(”([%w%s%p]+)", “%1”)
print(stringz)[/lua]

That will simply strip any anchor tags out.

[import]uid: 19626 topic_id: 15001 reply_id: 55496[/import]