Differences between matches with same RegEx [modified]
-
Guys, Seems quiet around here, but hey-ho...hopefully I'll get a response. OK - I have the following Regex: ^https?://([a-zA-Z0-9-_]*[/\.]{1})*([a-zA-Z]^\.)*(aspx)? Which I've created using an online regex builder[^] 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++.
modified on Friday, August 6, 2010 6:33 AM
-
Guys, Seems quiet around here, but hey-ho...hopefully I'll get a response. OK - I have the following Regex: ^https?://([a-zA-Z0-9-_]*[/\.]{1})*([a-zA-Z]^\.)*(aspx)? Which I've created using an online regex builder[^] 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++.
modified on Friday, August 6, 2010 6:33 AM
A shot in the dark. Try $ (matches end-of-string) at the end of your regex. Maybe one environment assumes it, the other not.
Software rusts. Simon Stephenson, ca 1994.
-
A shot in the dark. Try $ (matches end-of-string) at the end of your regex. Maybe one environment assumes it, the other not.
Software rusts. Simon Stephenson, ca 1994.
By jove I think he's got it! Good work fella...thanks a lot!
C# has already designed away most of the tedium of C++.