Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Regular Expressions
  4. Differences between matches with same RegEx [modified]

Differences between matches with same RegEx [modified]

Scheduled Pinned Locked Moved Regular Expressions
regexcsharpc++comsysadmin
3 Posts 2 Posters 11 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RichardGrimmer
    wrote on last edited by
    #1

    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

    P 1 Reply Last reply
    0
    • R RichardGrimmer

      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

      P Offline
      P Offline
      Peter_in_2780
      wrote on last edited by
      #2

      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.

      R 1 Reply Last reply
      0
      • P Peter_in_2780

        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.

        R Offline
        R Offline
        RichardGrimmer
        wrote on last edited by
        #3

        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++.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups