1 Reply Latest reply on Dec 8, 2009 5:04 AM by sss999sss

    Rplacing space with &nbsb; in html using regular expressions

    sss999sss

      Hi

      I want to replace space with &nbsb; in HTML.

       

      I used  the below method to replace space in my html file.

       

      var spacePattern11:RegExp =/(\s)/g; 

      str= str.replace(spacePattern," "

       

      Here str varaible contains below html file.In this html file i want to replace space present between " What number does this  represents" with &nbsb;

       

       

      <html>
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <title>Untitled Document</title>
      </head>

       

      <body>
      <b><TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Verdana" style = 'font-size:10px' COLOR="#0B333C" LETTERSPACING="0" KERNING="0"><B></B></FONT></P></TEXTFORMAT><TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Verdana" style = 'font-size:10px' COLOR="#0B333C" LETTERSPACING="0" KERNING="0"><B> What number does this Roman numeral represents MDCCCXVIII ?</B></FONT></P></TEXTFORMAT></b>
      </body>
      </html>

       

      But by using the above regular expression i am getting like this.

       

      <html>
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <title>Untitled Document</title>
      </head><body>
      <b><TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Verdana" style = 'font-size:10px' COLOR="#0B333C" LETTERSPACING="0" KERNING="0"><B></B></FONT></P></TEXTFORMAT><TEXTFORMAT LEADING="2"><P A LIGN="LEFT"><FONT FACE="Verdana" style = 'font-size:10px' COLOR="#0B333C" LETTERSPACING="0 " KERNING="0"><B> What number does this represents</B></FONT></P></TEXTFORMAT></b>
      </body>
      </html>

       

       

      Here what happening means it was replacing space with &nbsb; in HTML tags also.But want to replace space with &nbsb; present in the outside of the HTML tags.I want like this using regular expressions in FLEX

       


      <html>
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <title>Untitled Document</title>
      </head>
      <body>What number does this represents</body>
      </html>

       

      Hi,Please give me the solution to slove the above problem using regular expressions

       

      Thanks in Advance to all

       

      Regards

      ----------

      ssssssss

       

       

       

       

       

        • 1. Re: Rplacing space with &nbsb; in html using regular expressions
          sss999sss Level 1

          sorry i missed some information in above,The modified information was in red color

           

          Hi

          I want to replace space with &nbsb; in HTML.

           

          I used  the below method to replace space in my html file.

           

          var spacePattern11:RegExp =/(\s)/g; 

          str= str.replace(spacePattern," "

           

          Here str varaible contains below html file.In this html file i want to replace space present between " What number does this  represents" with &nbsb;

           

           

          <html>
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
          <title>Untitled Document</title>
          </head>

           

          <body>
          <b><TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Verdana" style = 'font-size:10px' COLOR="#0B333C" LETTERSPACING="0" KERNING="0"><B></B></FONT></P></TEXTFORMAT><TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Verdana" style = 'font-size:10px' COLOR="#0B333C" LETTERSPACING="0" KERNING="0"><B> What number does this Roman numeral represents MDCCCXVIII ?</B></FONT></P></TEXTFORMAT></b>
          </body>
          </html>

           

          But by using the above regular expression i am getting like this.

           

          <html>
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
          <title>Untitled Document</title>
          </head><body>
          <b><TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Verdana" style = 'font-size:10px' COLOR="#0B333C" LETTERSPACING="0" KERNING="0"><B></B></FONT></P></TEXTFORMAT><TEXTFORMAT LEADIN G="2"><P ALIGN="LEFT"><FONT FACE="Verdana" style = 'font-size:10px' COLOR="#0B33 3C" LETTERSPACING="0" KERNING="0"><B> What number does this represents</B></FONT></P></TEXTFORMAT></b>
          </body>
          </html>

           

           

          Here what happening means it was replacing space with &nbsb; in HTML tags also.But want to replace space with &nbsb; present in the outside of the HTML tags.I want like this using regular expressions in FLEX

           


          <html>
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
          <title>Untitled Document</title>
          </head>
          <body>What&nbsb;number&nbsb;does&nbsb;this&nbsb;represents</body>
          </html>

           

          Hi,Please give me the solution to slove the above problem using regular expressions

           

          Thanks in Advance to all

           

          Regards

          ----------

          ssssssss