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. C#
  4. Regular Expressions in C#

Regular Expressions in C#

Scheduled Pinned Locked Moved C#
csharphelpquestiondatabaseregex
8 Posts 3 Posters 0 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.
  • C Offline
    C Offline
    conrado7
    wrote on last edited by
    #1

    Does anyone of you can answer to my question? I want use regular expression in my text box to validate text. For example reg. expression like this : "[0-9][0-9]-[0-9][0-9][0-9]" accepts only for example "43-456" text. What if I enter "54-8f5" ? .NET Regular Expressions tells me that this text is not correct. But it doesn`t tell me which character is invalid. My problem is that I want .NET Regular Expressions show me which character (which character index in this incorrect string) is invalid. Please help me... -- modified at 15:53 Thursday 16th March, 2006 Is it possible with .NET regular expressions?

    C L 2 Replies Last reply
    0
    • C conrado7

      Does anyone of you can answer to my question? I want use regular expression in my text box to validate text. For example reg. expression like this : "[0-9][0-9]-[0-9][0-9][0-9]" accepts only for example "43-456" text. What if I enter "54-8f5" ? .NET Regular Expressions tells me that this text is not correct. But it doesn`t tell me which character is invalid. My problem is that I want .NET Regular Expressions show me which character (which character index in this incorrect string) is invalid. Please help me... -- modified at 15:53 Thursday 16th March, 2006 Is it possible with .NET regular expressions?

      C Offline
      C Offline
      Curtis Schlak
      wrote on last edited by
      #2

      No. Sorry. You can only perform positive matching with .NET REs.

      C 1 Reply Last reply
      0
      • C Curtis Schlak

        No. Sorry. You can only perform positive matching with .NET REs.

        C Offline
        C Offline
        conrado7
        wrote on last edited by
        #3

        Are you absolutely sure? Anyway...Thank you very much... You let me safe so much time of my research...

        1 Reply Last reply
        0
        • C conrado7

          Does anyone of you can answer to my question? I want use regular expression in my text box to validate text. For example reg. expression like this : "[0-9][0-9]-[0-9][0-9][0-9]" accepts only for example "43-456" text. What if I enter "54-8f5" ? .NET Regular Expressions tells me that this text is not correct. But it doesn`t tell me which character is invalid. My problem is that I want .NET Regular Expressions show me which character (which character index in this incorrect string) is invalid. Please help me... -- modified at 15:53 Thursday 16th March, 2006 Is it possible with .NET regular expressions?

          L Offline
          L Offline
          leppie
          wrote on last edited by
          #4

          conrado7 wrote:

          Is it possible with .NET regular expressions?

          Yes, but a bit long winded. "(?(?[0-9])(?**[0-9])-(?[0-9])(?[0-9])(?[0-9]))" 1. Run with explicit capture. 2. Validate "valid" group. 3. If fail, validate each subgroup. Depending on the actual RE it mite be easier to just handwrite a 'parser'. :)

          **

          xacc.ide-0.1.3.2

          C 1 Reply Last reply
          0
          • L leppie

            conrado7 wrote:

            Is it possible with .NET regular expressions?

            Yes, but a bit long winded. "(?(?[0-9])(?**[0-9])-(?[0-9])(?[0-9])(?[0-9]))" 1. Run with explicit capture. 2. Validate "valid" group. 3. If fail, validate each subgroup. Depending on the actual RE it mite be easier to just handwrite a 'parser'. :)

            **

            xacc.ide-0.1.3.2

            C Offline
            C Offline
            conrado7
            wrote on last edited by
            #5

            You sugested that in a more difficult regular expression the better thing to do is to write my own regular expression parser? Do you have any idea how I suppose to do this?

            L 1 Reply Last reply
            0
            • C conrado7

              You sugested that in a more difficult regular expression the better thing to do is to write my own regular expression parser? Do you have any idea how I suppose to do this?

              L Offline
              L Offline
              leppie
              wrote on last edited by
              #6

              conrado7 wrote:

              You sugested that in a more difficult regular expression

              I meant an easier RE as per your example. It will probably just be easier to read the string char by char :)

              xacc.ide-0.1.3.2

              C 1 Reply Last reply
              0
              • L leppie

                conrado7 wrote:

                You sugested that in a more difficult regular expression

                I meant an easier RE as per your example. It will probably just be easier to read the string char by char :)

                xacc.ide-0.1.3.2

                C Offline
                C Offline
                conrado7
                wrote on last edited by
                #7

                I`ve been wondering about creating my own parser, but in more difficult RE it`s very hard to build it. For e.g. ^(/d{2}-/d{3}){3,}$ Reg Exp... How can my parser read this to show me wich character is invalid? Any ideas?

                L 1 Reply Last reply
                0
                • C conrado7

                  I`ve been wondering about creating my own parser, but in more difficult RE it`s very hard to build it. For e.g. ^(/d{2}-/d{3}){3,}$ Reg Exp... How can my parser read this to show me wich character is invalid? Any ideas?

                  L Offline
                  L Offline
                  leppie
                  wrote on last edited by
                  #8

                  The only way is to use sub group matching as per my example earlier.

                  xacc.ide-0.1.3.2

                  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