I'm not in the least bit supprised it doesn't work as you expected. It isn't a valid regex.
Go to www.ultraPico.com[^] and D/L a copy of Expresso - it examines, designs and explains regexes. It's free, and I use it a lot. I really wish I'd written it!
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
It's intended to match urls on either www. or local network, with or without a page (.aspx) on the end (so either www.site.com/ or www.site.com/page.aspx). The problem I have is that for all cases it seems to work correctly, until I drop it into my C# / Silverlight app (with the 2 x \ escaped as \\).
The problem is that under the regex builder, a .aspx is fine, a .aspxs is flagged as not matching - which is exactly what I need...however, in c# the aspxs is not flagged as invalid.
I think I can see why - because the s is part of the group, it's permitted - so I'm trying to essentially do an Optional literal string...the ? to make it optional, the brackets to apply to the group...but c# seems to be percieving it more as [aspx]* . If I remove the bracket, then the ? only then applies to the x on the end (as with the s in https at the start)...
Any ideas what I've missed here?
C# has already designed away most of the tedium of C++.
it must be a small problem that drives me crazy here...
From a text file like the sample given below, the following regular expression extracts the 'Grp' group well, but the 'Entr' group would always be empty. Maybe someone else can see where my error is? Actually, as a final result I'd also like to extract the entrie's name and its value (i.e. befor/after the "=") into different groups. Are any regex experts around who probably see more?
Dim regex = New Regex("\[(?<Grp>.*)\](?<Entr>.*)
is supposed to give me back the groups and entries in an ini-file like structure, no? It seems as if \[ and \] lead to something which I can't find in any reference. Btw I built the regex with Expresso.
Happy day ! I could resolve a part of my regex task in Expresso.
For the record and other users: Obviously ".*" for "any character / any number of repetitions" is not good enough to capture a CRLF! Trying to capture it with \r wasn't the right thing either, it took "\r\n" to match the group together with the first line! Here's the current status of the regex:
I'm not really a regex expert, but I would tackle your problem with two regex and two foreach; the first regex would locate groups, the second would parse the key=value pairs within a group. I've never seen this done with a single regex.
BTW: I don't like your \r\n stuff at all. One normally uses the symbols for start-of-line (^) and end-of-lin ($)e, avoiding problems with matching things on the first line and last line (your input may or may not end on \r or \r\n).
FYI: I have some similar regex stuff in my article CP Vanity[^] which scrapes some of the CodeProject web pages. Similiar meaning two regexes, two foreach loops.