473,397 Members | 2,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Regex match all whitespace before character

I'm trying to remove all whitepace in an HTML-formatted string, except within the actual content.

so I want to get:
Expand|Select|Wrap|Line Numbers
  1. <p>   <b>some text</b> </p>
to look like
Expand|Select|Wrap|Line Numbers
  1. <p><b>some text</b></p>
I've been trying something like:
Expand|Select|Wrap|Line Numbers
  1. Regex r = new Regex(@"/s<);
  2. r.Replace(str, "<");
  3.  
with the idea being to replace all the whitespace immediately preceeding the "<" character. That would be fine for what I'm doing, but no expression using *,+,.,?, etc, is working. The best I'm able to get is removing the first whitespace before an "<" character, but sometimes there's more than one.

Please help, the only Regex expressions I'm coming up with right now are "@$*%!!!"
Mar 25 '08 #1
1 1455
Shashi Sadasivan
1,435 Expert 1GB
@(>){ }*(<b)$ or
@(/b>){ }*(<)$

Should be somewhat like that.

the first one @(>){ }*(<b)$ checks that part of the string that starts with >
and ends with <b with spaces in between.

the second part @(/b>){ }*(<)$ finds the string that starts with /b> and ends with <

My regex is pretty shady at the moment...so @ represents the string that has to match starts with the charecters specified after that and $ repreents the chrachter which should contain at the end of the string being searched / matched for.

Hope this helps.
Mar 26 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Seb | last post by:
Hi, Has anyone an idee how i can replace every character in a string if it is not alphanumeric ? something like eregi_replace, but i don't know how i say in regex NOT. Tnx
5
by: lawrence | last post by:
When users enter urls or other long strings it can destroy the formatting of a page. A long url, posted in a comment, can cause page distortions that make the page unreadable, till the website...
7
by: bill tie | last post by:
I'd appreciate it if you could advise. 1. How do I replace "\" (backslash) with anything? 2. Suppose I want to replace (a) every occurrence of characters "a", "b", "c", "d" with "x", (b)...
10
by: John A Grandy | last post by:
What's the proper way to write a validation regex so that all leading and trailing spaces are trimmed before evaluation ? Thanks.
17
by: clintonG | last post by:
I'm using an .aspx tool I found at but as nice as the interface is I think I need to consider using others. Some can generate C# I understand. Your preferences please... <%= Clinton Gallagher ...
11
by: Steve | last post by:
Hi All, I'm having a tough time converting the following regex.compile patterns into the new re.compile format. There is also a differences in the regsub.sub() vs. re.sub() Could anyone lend...
6
by: Lubomir | last post by:
Hi, I am using the following pattern: "\\b" + MySttring + "\\b" If MyString is "one", this should pick up whole words like "one". The problem is, it will pick up also the word: "one.two"...
3
by: =?Utf-8?B?TmF2ZWVu?= | last post by:
Not sure if this is the right forum for this question but couldn'd find another newsgroup. I am new to Regular expressions and would like help in deciding which pattern allows me to split a...
3
by: Jeff | last post by:
I'm parsing this: name="value" and sometimes it looks like this: name2="value2 without the closing '"'. I don't want to capture the end quote.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.