Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Regular expression - Remove double spaces inside HTML tags

Posted on 2005-05-05
3
Medium Priority
?
1,123 Views
Last Modified: 2012-06-27
Hi,

I need a regular expression to remove double spaces inside HTML tags.

E.G:

<font         face="arial">
<font     size    =    2>

I need to run the regexp and get:
<font face="arial">
<font size = 2>

Cheers.
0
Comment
Question by:richardoc
  • 2
3 Comments
 
LVL 13

Expert Comment

by:nurbek
ID: 13936217
you may try replace function, or trim

str = Replace (myStr,"  "," ")

str = Trim(myStr)

Response.Write(Server.HTMLEncode(str))
0
 
LVL 10

Accepted Solution

by:
ThaSmartUno earned 1000 total points
ID: 13936309
<%

s="blah       blah blah  blah" & vbCrLf & _
    "<font         face=""arial"">" & vbCrLf & _
    "<font     size    =    2>" & vbCrLf

s = RemoveInHTML(s,"[ ]+")

Response.Write Server.HTMLEncode(s)

Function RemoveInHTML(str,what)
  Dim r, ms, itm, n
  Set r = New RegExp

  r.Global = True
  r.Pattern = "<(.*?)>"
  Set ms = r.Execute(str)

  r.Pattern = what

  n=str
  For Each itm In ms
    n=Replace(n, itm.Value, r.Replace(itm.Value," "))
  Next

  RemoveInHTML = n
End Function

%>

(this may be too much, there might be a simplier way)
0
 
LVL 10

Expert Comment

by:ThaSmartUno
ID: 13936387
If you use replace(nurbek's comment) ... as long as you loop it, it will kind of work

r="blah       blah blah  blah" & vbCrLf & _
    "<font         face=""arial"">" & vbCrLf & _
    "<font     size    =    2>" & vbCrLf

Do While InStr(r,"  ") > 0
  r = Replace(r,"  ", " ")
Loop

This will Also remove the double spaces outside the HTML code also

I could not tell you wish would be faster or ideal, since I do not know =)

But good luck.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Loops Section Overview
Screencast - Getting to Know the Pipeline

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question