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. Reg Ex

Reg Ex

Scheduled Pinned Locked Moved C#
regex
9 Posts 6 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.
  • A Offline
    A Offline
    Aslesh
    wrote on last edited by
    #1

    How can we write a regular expression which accepts only alphabets or digits or alphanumeric(alphabets+digits)

    P L 2 Replies Last reply
    0
    • A Aslesh

      How can we write a regular expression which accepts only alphabets or digits or alphanumeric(alphabets+digits)

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

      Usually with a text editor, but you could use Expresso[^].

      A 1 Reply Last reply
      0
      • P PIEBALDconsult

        Usually with a text editor, but you could use Expresso[^].

        A Offline
        A Offline
        Aslesh
        wrote on last edited by
        #3

        i have written like this ^[A-Z0-9]$ is this valid?

        G K 2 Replies Last reply
        0
        • A Aslesh

          i have written like this ^[A-Z0-9]$ is this valid?

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          Santhapur wrote:

          i have written like this ^[A-Z0-9]$ is this valid?

          Yes, that is correct. It can also be written ^[A-Z\d]$.

          Despite everything, the person most likely to be fooling you next is yourself.

          1 Reply Last reply
          0
          • A Aslesh

            i have written like this ^[A-Z0-9]$ is this valid?

            K Offline
            K Offline
            Kythen
            wrote on last edited by
            #5

            Yes, though you may want to change it to ^[A-Za-z0-9]$ to allow lower-case letters as well. If you want to allow more than one letter or digit in a match, add a + before the $so that the expression looks like this: ^[A-Za-z0-9]+$ If you're looking for some helpful .NET regex tools, I use the free Rad Software Regular Expression Designer[^] to help build and test regular expressions.

            W 1 Reply Last reply
            0
            • A Aslesh

              How can we write a regular expression which accepts only alphabets or digits or alphanumeric(alphabets+digits)

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

              ^\w+$

              xacc.ide - now with TabsToSpaces support
              IronScheme - 1.0 alpha 4a out now (29 May 2008)

              G 1 Reply Last reply
              0
              • K Kythen

                Yes, though you may want to change it to ^[A-Za-z0-9]$ to allow lower-case letters as well. If you want to allow more than one letter or digit in a match, add a + before the $so that the expression looks like this: ^[A-Za-z0-9]+$ If you're looking for some helpful .NET regex tools, I use the free Rad Software Regular Expression Designer[^] to help build and test regular expressions.

                W Offline
                W Offline
                Wendelius
                wrote on last edited by
                #7

                Seems like a very good tool. Thanks for the info! Mika

                1 Reply Last reply
                0
                • L leppie

                  ^\w+$

                  xacc.ide - now with TabsToSpaces support
                  IronScheme - 1.0 alpha 4a out now (29 May 2008)

                  G Offline
                  G Offline
                  Guffa
                  wrote on last edited by
                  #8

                  leppie wrote:

                  ^\w+$

                  As that doesn't do exactly what the OP asked for, perhaps you should have explained what it does... It allows letters, digits and underscore, i.e. it's equivalent to ^[A-Za-z0-9_]+$.

                  Despite everything, the person most likely to be fooling you next is yourself.

                  L 1 Reply Last reply
                  0
                  • G Guffa

                    leppie wrote:

                    ^\w+$

                    As that doesn't do exactly what the OP asked for, perhaps you should have explained what it does... It allows letters, digits and underscore, i.e. it's equivalent to ^[A-Za-z0-9_]+$.

                    Despite everything, the person most likely to be fooling you next is yourself.

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

                    OK, I actually didn't know about the underscore :-O Damn rusty brain ;P

                    xacc.ide - now with TabsToSpaces support
                    IronScheme - 1.0 alpha 4a out now (29 May 2008)

                    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