1 Reply Latest reply on Feb 17, 2010 12:12 PM by NonTakenUserName

    Simple syntax question

    stabbylorenzo

      Hey everyone,

       

      I'm trying to do a match/replace with a pattern that contains special characters, and running into syntax errors in a Flex 3 app. I just want the following regex to compile... (while also replacing html tags with "")

       

      value.replace(/</?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)/?>/g, "");

      On a side note, the pattern /<.*?>/g wouldn't work in cases where there are html entities between tags, 
      like so:
      
      <TEXTFORMAT LEADING="2">
      <P ALIGN="LEFT">
      <FONT FACE="Arial" SIZE="11" COLOR="#4F4A4A" LETTERSPACING="0" KERNING="0"><one</FONT>
      </P>
      </TEXTFORMAT><TEXTFORMAT LEADING="2">
      <P ALIGN="LEFT">
      <FONT FACE="Arial" SIZE="11" COLOR="#4F4A4A" LETTERSPACING="0" KERNING="0">two</FONT>
      </P>
      </TEXTFORMAT>
      
      The first regex would get both "<one" and "two", but the second would only get "hi"

      Thanks!

      Stabby L

        • 1. Re: Simple syntax question
          NonTakenUserName Level 1

          This one is working for me:

           

          value.replace(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/g, "");

           

          (Same as yours, but escaping the /)

           

          Are < and > the only special characters that can be in between tags? in that case, even if /<.*?>/g wouldn't work, could /<.[^<>]*?>/g be enough?