Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi , following is the code :
//throw new NotImplementedException();
           Regex rdr = new Regex(@"<td><a href=""/wiki/\w+"" title=""(?<Title>\w+)"">""(?<TitleHR>.+?)""</a>");
           Match mt = rdr.Match(line);

           //if (mt.Success)
           //{
             //   AddState(mt.Groups[0].Value , mt.Value);
           //}

           if (rdr.IsMatch(line))
           {
               //Match mtc;
               //mtc = rdr.Match(line);
               //AddState(mt["Title"].Value, mt[1].Value);
               AddState(mt.Groups["Title"].Value, mt.Groups["TitleHR"].Value);

           }

Now when i try to match line the line doesnt match. I get ismatch as false

Following is the line :
<a href="/wiki/Alabama" title="Alabama">Alabama</a>
Posted
Updated 11-Apr-13 9:12am
v3
Comments
Richard C Bishop 11-Apr-13 11:11am    
If you want a substring just use the SubString method.
shanalikhan 11-Apr-13 14:56pm    
i want to get 1+ string from it. how i can do it by subsstring
CHill60 11-Apr-13 11:15am    
Can you post the sample data that you are using (line)
shanalikhan 11-Apr-13 14:56pm    
Please have a look , i have updated the question

1 solution

You haven't used groups in your Regex! So all you will get is the whole string matched.
I'm just guessing that you want to break out the title and the human readable segment separately?
Try this:
<a href="/wiki/\w+" title="(?<Title>\w+)">(?<TitleHR>.+?)</a>

This breaks out two groups: "Title" and "TitleHR" which may be what you wanted.

If you are going to use regexes, then get a copy of Expresso [^] - it's free, and it examines and generates Regular expressions. I use it, and wish I'd written it!
 
Share this answer
 
v2
Comments
shanalikhan 11-Apr-13 14:57pm    
I tried it but im gettting ismatch as false by running the same code. Line to parse is also written. Please have a look on it.
OriginalGriff 11-Apr-13 15:07pm    
Try the edited version above - the auto tag completer added a pile of cr@p and I didn't notice... Try it in Espresso first.
CHill60 12-Apr-13 6:33am    
My +5 - thought it was something to do with no groups but wasn't confident enough - so I've learned something today as well - thank you!
OriginalGriff 12-Apr-13 6:57am    
You're welcome!

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