Extract the in-betweens...
-
Hey All! :-D I've been readin' up on Regular Expressions alot lately because I need to Extract words inbetween HTML tags for example I need to extract the words 'extract this!': Extract this! and also: Extract this URL I have followed many examples and read MSDN and I just can't get it to work. Can anyone please shed some light on this matter? Thanks in advance Jay. j.t.
-
Hey All! :-D I've been readin' up on Regular Expressions alot lately because I need to Extract words inbetween HTML tags for example I need to extract the words 'extract this!': Extract this! and also: Extract this URL I have followed many examples and read MSDN and I just can't get it to work. Can anyone please shed some light on this matter? Thanks in advance Jay. j.t.
Use regex grouping to match the bits you want to keep and build a new string, or to match the bits you want to remove, and then remove them.
Christian Graus Driven to the arms of OSX by Vista. "I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
-
Use regex grouping to match the bits you want to keep and build a new string, or to match the bits you want to remove, and then remove them.
Christian Graus Driven to the arms of OSX by Vista. "I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
-
Hey All! :-D I've been readin' up on Regular Expressions alot lately because I need to Extract words inbetween HTML tags for example I need to extract the words 'extract this!': Extract this! and also: Extract this URL I have followed many examples and read MSDN and I just can't get it to work. Can anyone please shed some light on this matter? Thanks in advance Jay. j.t.
jay_t55 wrote:
need to extract the words 'extract this!': Extract this!
Here you go..
string str = "<title>Extract this!</title>"; Regex RE = new Regex(@"(<title> )(\\w|\\S|\\s )+(</title> )"); MatchCollection MC = RE.Matches(str); if (MC.Count == 0) MessageBox.Show("No match"); foreach (Match M in MC) { string trimStr = "</title>"; MessageBox.Show(M.ToString().Trim(trimStr.ToCharArray())); }
8.Kelvin()
{
while (!(the machine can program itself))
Wont_stop_coding = true;
} -
jay_t55 wrote:
need to extract the words 'extract this!': Extract this!
Here you go..
string str = "<title>Extract this!</title>"; Regex RE = new Regex(@"(<title> )(\\w|\\S|\\s )+(</title> )"); MatchCollection MC = RE.Matches(str); if (MC.Count == 0) MessageBox.Show("No match"); foreach (Match M in MC) { string trimStr = "</title>"; MessageBox.Show(M.ToString().Trim(trimStr.ToCharArray())); }
8.Kelvin()
{
while (!(the machine can program itself))
Wont_stop_coding = true;
} -
Hey All! :-D I've been readin' up on Regular Expressions alot lately because I need to Extract words inbetween HTML tags for example I need to extract the words 'extract this!': Extract this! and also: Extract this URL I have followed many examples and read MSDN and I just can't get it to work. Can anyone please shed some light on this matter? Thanks in advance Jay. j.t.
What you want is an HTML parser (google is your friend). Don't mess around with regex because you'll spend a lot of time trying to figure it out. Believe me - downloading a parser will be much faster.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 -
What you want is an HTML parser (google is your friend). Don't mess around with regex because you'll spend a lot of time trying to figure it out. Believe me - downloading a parser will be much faster.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001Hear hear! This is a wheel best not reinvented.