Regex Favorite parser

G

Guest

I am creating some program which should get URL param from IE favorites
files. And I need create correct Regex for this.

Now I have this

string WorkString =
@"URL=http://www.test.com/homepage.asp?cool=rere%*&*#&(@&=sdfsdfsd%"
Regex URLrequest = new Regex(@"\s*URL\s*=\s*(?<URL>[\w\W]*)\s*",
RegexOptions.Compiled);
Match matcher = URLrequest.Match(WorkString);
if (matcher.Success)
{
string url = matcher.Result("${URL}");
}

And I have one problem with this
if the line string is "BASEURL=http://www.test.com/homepage...."
it works too.
But I need only make Regex return Success only when string is " URL="
and false when " BASEURL=http" or " XXS#URL = "

How I should modify Regex for this? How put negative condition at all?
 
P

PlatinumBay

SushiSean,

There is a great tool I use for RegEx sometimes:
http://www.ultrapico.com/Expresso.htm

Here is the base for recognizing a URL:
(?<Protocol>\w+):\/\/(?<Domain>[\w.]+\/?)\S*(?x)

What you need to do is match the specific characters before it. If I
understand your example below, you want to match " URL=", so this would be
^\s{3}URL\=(?<Protocol>\w+):\/\/(?<Domain>[\w.]+\/?)\S*(?x)$

You may also want to use IgnoreCase and IgnorePatternWS.

Hope this helps,


Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top