Click here to Skip to main content
15,888,208 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I am finding it impossible to come up with a pair of regular expressions to remove sequences of more than one space and replace them with single spaces in a HTML document loaded into Visual Studio 2010.

I've read all the help (including using :b which is supposed to match a space), and I just can't get it to work. Can anyone offer any help with this, please? It's driving me nuts.

Kind wishes, Patrick
Posted

1 solution

Your search pattern should be :b+ (one or more spaces), and your replacement just a single space character, or whatever other string you want.
 
Share this answer
 
Comments
Patrick Skelton 6-Dec-12 11:50am    
Thank you for your answer. Unfortunately, I have already tried that. When it gets to two spaces in a row, it matches only the second, so when I replace it with a single space, I get back the same.

I wonder if I can try replacing it with nothing and applying the same replace over and over until I have got rid of the longest string of spaces (which is about 16, I think). Sort of a functional programming approach.

I'll try it now.

- Patrick
Richard MacCutchan 6-Dec-12 11:59am    
Well I have just tested it with :b+ and a single space as replacement character and it correctly replaces two spaces by one.
Patrick Skelton 6-Dec-12 12:44pm    
Yes, thanks, Richard. Please see my comments below why it wasn't working for me.

- Patrick
Patrick Skelton 6-Dec-12 11:52am    
Doh! No - obviously that doesn't work, because it gets rid of all spaces.
Patrick Skelton 6-Dec-12 12:12pm    
I should have done this before. Checking the hex for the file, it turns out where there are multiple spaces, all but one are 0x2e (non-breaking-space character). I can find these easily enough, using \x00a0, but when I leave the Replace With box blank, the Replace button is greyed out, so I cannot replace these with nothing - even though that's exactly what MSDN says you can do.

Grrr ....

- Patrick

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900