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 <a href="http://www.mysite.com">Some Text</a>
blah blah blah.
I want to remove the link, leaving the text.
Here is the code I'm trying to use:
1 | storyBody = story.content_encoded:gsub("<a%w+>(%w+)<%/a>", "%1") |
Wow, must be really some censored content, it has an extra x after xxx ;)
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,
?:)
Yea, its some seriously erotic text :-P
I'm using gsub because I want to remove the link, but leave the text that the link wraps, in other words:
substitute:
<a href="http://mysite.com">Click Here</a>
with
Click Here
I suppose I could do that with .find and then some substring operations, but substitute seems like the route to go.
Try this,
1 2 3 4 | stringy = "<a href='http://www.oz-apps.com/page/1.html'> test </a>" for k, v in string.gmatch(stringy, "%S*") do print(k) end |
This regex will match anything between > and <
1 | >(.*?)< |
Remember that this site is your best friend when testing out regex expressions:
Actually this will probably work for me:
1 2 3 | stringy = "blah blah blah <a href='http://www.oz-apps.com/page/1.html'>test</a> blah blah blah " stringz = stringy:gsub("<a[%w%s%p]+>([%w%s%p]+)</a>", "%1") print(stringz) |
send message and call to a person
Forum: Report Spam + PM
[INSTALL_PARSE_FAILED_NO_CERTIFICATES]
[SOLVED] Director ERROR: Failed to execute new( params ) function on 'screen1'
Too many (200) local variables
Corona SVG Level Builder released. Drag and drop physics level editor with Inkscape and SVG.
Small bug in Collectible Items example
Pivot Joints and apparent elasticity
Can't make removeSelf() delayed