RegEx to remove span tags

I will be reading in a text file, creating an array and need to remove the span tags, leaving the text string in between. Basically the line might look like this:
Some text here and I want to just be left with the string “Some text here”.
I know I can remove the end tag by replacing “” with “”, but the beginning tag is a bit more than I’ve done with RegEx. I thought I could use something like:

rg.searchPattern = "<span(.+)>" for i = 0 to ubound(myArray) myMatch = rg.search(myArray(i)) if myMatch <> nil then myArray(i) = replace(myArray(i),rg.searchPattern,"") end if next
to get rid of the first half of the span tag, but it’s not working. I’m still getting the complete span tag along with the text string. I’ve also tried other combinations.

https://forum.xojo.com/15994-removing-nested-span-tags-in-text/0

I found that but it didn’t help. I just figured it out, though. In my replace statement I instead used “myMatch.subExpressionString(0)” instead of the rg.searchpattern. Now it works. Here is my working code:

rg.searchPattern = "<span(.+)>" for i = 0 to ubound(myArray) myArray(i) = replace(myArray(i),"</span>","") myMatch = rg.search(myArray(i)) if myMatch <> nil then myArray(i) = replace(myArray(i),myMatch.subExpressionString(0),"") msgBox myArray(i) end if next

or just grab kems regexrx which has a pile of prebuilt templates for stuff like this :slight_smile: