473,395 Members | 1,647 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,395 software developers and data experts.

How to work with Regex properly?

Hi ALL.

I would like to strip out all comments from some HTML source code. E.g.,

html = "__block 1__<!--....-->__block 2__<!--...-->__block 3__"

then call

Regex.Replace(sString, "<!--[^>]*-->", "") returns

"__block 1__block 3__"

, but I want to receive

"__block 1____block 2____block 3__"

Surely, it's can be realized with string operations, but is it possible to
do it by the Regexp?

More commonly, in Regex language we can use that construction: [^(class of
symbols)], that means "match any 1 symbol excluding any of (class of
symbols)". How can man define the following "match any symbol-sequence that
differs from the given (string-longer-then-1-symbol)"??

Thanks
Jul 21 '05 #1
1 1164
I think if you use:

"<!--.*?-->"

as your pattern, you'll get the behavior you want. The '?' makes *
non-greedy, so it matches the shortest possible string.

--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://blogs.gotdotnet.com/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights.
"Evgeny Zoldin" <ez*****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hi ALL.

I would like to strip out all comments from some HTML source code. E.g.,

html = "__block 1__<!--....-->__block 2__<!--...-->__block 3__"

then call

Regex.Replace(sString, "<!--[^>]*-->", "") returns

"__block 1__block 3__"

, but I want to receive

"__block 1____block 2____block 3__"

Surely, it's can be realized with string operations, but is it possible to
do it by the Regexp?

More commonly, in Regex language we can use that construction: [^(class of
symbols)], that means "match any 1 symbol excluding any of (class of
symbols)". How can man define the following "match any symbol-sequence that differs from the given (string-longer-then-1-symbol)"??

Thanks

Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: jeevankodali | last post by:
Hi I have an .Net application which processes thousands of Xml nodes each day and for each node I am using around 30-40 Regex matches to see if they satisfy some conditions are not. These Regex...
7
by: Beeeeeeeeeeeeves | last post by:
Hi I do mostly programming in VB6 and C# although I like to dabble in C++ now and again, I was just wondering what is a good* regular expression library to use for C++, given that I DON'T want to...
4
by: Brent | last post by:
Take this string: "---------------------------------------- " (i.e., hyphens followed by a newline ) I thought I could match it simply with this Regex: "-*?\n"
6
by: Chris Anderson | last post by:
Anyone know of a fix (ideally) or an easy workaround to the problem of escape characters not working in regex replacement text? They just come out as literal text For example, you'd think that thi...
1
by: Evgeny Zoldin | last post by:
Hi ALL. I would like to strip out all comments from some HTML source code. E.g., html = "__block 1__<!--....-->__block 2__<!--...-->__block 3__" then call Regex.Replace(sString,...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
7
by: MattMika | last post by:
Can anyone point out the problem with this? The commented regex var and if statement dont work and break the GroupName check when uncommented. I tested the AccessCodeRegxp with preg_match and it...
1
by: TtfnJohn | last post by:
I have two small scripts that while on the surface should both work the problem is they don't. Here's the first one: import re testString = 'Thap,fpvi,*!wtyd@*.dip.t-dialin.net:*!ylx@*.dip.t-...
3
by: =?Utf-8?B?TWFya19C?= | last post by:
The following is working for me but I want to include numbers in scientific notation. public double Evaluate( string expr ) { const string Num = @"(\-?\d+\.?\d*|\-?\.\d+)" Regex reMulDiv = new...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.