views:

98

answers:

1

I am a bit confused how to best use a Regular Expression and hope I can get some help I want to extract a URL value from an INI File as such:

[DEFAULT]
BASEURL=http://www.stackoverflow.com/
[InternetShortcut]
URL=http://www.stackoverflow.com/

So I can get the URL value as the only Match from the Regular expression - but I don't understand enough about them (yet) to do this.
I have seen RegEx examples that will parse any INI file and get the Name, Value Pairs I just want to get the URL value only from a file no matter what else it contains.
My aim is to have something like this:

Dim _pattern As New Text.RegularExpressions.Regex("RegEx")
Dim _url As String = _pattern.Match(iniContentString).Value

It seems simple but I cannot seem to create a specific case RegEx where I want everything from "URL=" to the vbCrLf at the End to be my "Match".
I have refered to Regular-Expressions.info which has been a help before but still cannot get this simple example to work.

+1  A: 

Like this:

New Regex("^URL=(.*)$", RegexOptions.Multiline).Match(iniContent).Groups[1].Value

Note that this will match any URL= line, whatever section it's in.
If that's not what you want, please tell me.

EDIT: It should actually be .Groups[1].Value; this will not include URL=.

SLaks
This is more like what I needed, I'd only ever used them for characters not whole strings. This does work but I still get the "URL=" part - could this be excluded, otherwise I'll use a String Replace to get rid of it and mark as answer.
RoguePlanetoid
Thanks for the Edit, the URL and Match are two seperate groups - I always wondered if there was a "returned" part of a RegEx. Did not know that, this now works!
RoguePlanetoid