By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,424 Members | 1,375 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,424 IT Pros & Developers. It's quick & easy.

Regular Expression Pattern Help

P: n/a
Hello,
i want to parse some html with regex and have the following problem:
--- html to parse start ---

some text <span class="x">
some text with linebreaks
and tabs and <b>tags <i>in it</i>
goes here
</span> another text

--- html to parse end ---
Now my question: How do I have to write the pattern so I get
"some text with linebreaks and tabs and <b>tags <i>in it</i> goes here"
as a match?

TIA Martin
Nov 15 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
I highly recommend getting Regular Expression Workbench by Eric Gunnerson .
It helps a lot with this sort of stuff.
http://www.gotdotnet.com/Community/U...1-4ee2729d7322

The important thing is to set RegexOptions to SingleLine. Another important
note is to use .*? to match zero or more character between span tags, but
non-greedy (the ? makes it non greedy) that is- match the next </span> tag
found.

System.Text.RegularExpressions.Regex regex = new
System.Text.RegularExpressions.Regex(@"<span class="x">(?<Text>.*?)</span>",
System.Text.RegularExpressions.RegexOptions.Single line);

Match match = regex..Match(str);

It will create a capture called Text. see ms help for Match.Captures for
what to do with the result of the above line.

ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/cpref/html/frlrfsystemtextreg
ularexpressionsgroupclasscapturestopic.htm

Hope that gets you started!

Mike Mayer - Visual C# MVP
http://www.mag37.com/csharp/
mi**@mag37.com

"Martin Andert" <ma***********@gmx.de> wrote in message
news:9a**************************@posting.google.c om...
Hello,
i want to parse some html with regex and have the following problem:
--- html to parse start ---

some text <span class="x">
some text with linebreaks
and tabs and <b>tags <i>in it</i>
goes here
</span> another text

--- html to parse end ---
Now my question: How do I have to write the pattern so I get
"some text with linebreaks and tabs and <b>tags <i>in it</i> goes here"
as a match?

TIA Martin

Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.