Jump to content
xisto Community
Sign in to follow this  
CarlowOlson

I Need Help Writing A Very Simple Regular Expression?

Recommended Posts

Hello Guys,There will be multiple instances of this line in the string I'm parsing.a href="link" class="l"What I need is to pull link out of the string.Here's the regex I have now, but my tester says it's not valid./^a href\="(.*?)" class\=l$/mgI'm using C# for this application.Thanks in advanceCarlow Olson

Share this post


Link to post
Share on other sites

Hello Guys,

 

The .NET System.Text.RegularExpressions tools do not use /-delimited strings for regular expressions. Save that for javascript. Remove the leading / and the trailing /mg.

 

Also, the group (.*?) does not make sense. .* is already "optional in that the * allows 0 occurances of the . to match. Remove the ?.

 

Do you really want to match an empty string here? If not, use (.+) instead.

 

When you type this into a C# literal, use @-quoting rather than regular C/C++ style quoting. The leading @ avoids all processing of \ escapes. To get a quote in the string, type a double quote. For example:

 

string pattern = @"^a href=""(.*)"" class=I";

 

For your tester, just type the string contents: <a href="(.*)" class=I>, without the <> brackets shown here.

 

Thanks and Regards

Tony Mccallum

 

Mac Notebook

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.