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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Regular Expression ?

Regular Expression ?

Scheduled Pinned Locked Moved C#
regexhelpquestion
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.
  • S Offline
    S Offline
    Skoder
    wrote on last edited by
    #1

    Hello, i didnt really know where to post this. Soo hope it is okay that i have posted it here. I hope that someone can help me with this regular expression which is giving me a lot of trouble. It should match +-:._ "space" a-z A-Z 0-9 in any given order or combination. There have to be at least one of the following characters a-z A-Z 0-9 though. Spaces are accepted but not as the start or end character. Also there can not be 2 spaces just after eachother. Right now i have the following regular expression which does all of it except there can be more than 1 spaces in a row: ^(?! )[ \+\.\-:\w]*(?=[a-zA-Z0-9]+)[ \+\.\-:\w]*(?

    G M 2 Replies Last reply
    0
    • S Skoder

      Hello, i didnt really know where to post this. Soo hope it is okay that i have posted it here. I hope that someone can help me with this regular expression which is giving me a lot of trouble. It should match +-:._ "space" a-z A-Z 0-9 in any given order or combination. There have to be at least one of the following characters a-z A-Z 0-9 though. Spaces are accepted but not as the start or end character. Also there can not be 2 spaces just after eachother. Right now i have the following regular expression which does all of it except there can be more than 1 spaces in a row: ^(?! )[ \+\.\-:\w]*(?=[a-zA-Z0-9]+)[ \+\.\-:\w]*(?

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

      Handle the spaces as a complement to the characters. Each character (except the first) can optionally be preceded by a single space. ^[0-9A-Za-z0-9]( [\w+\-:\.])*$ Less is more. ;) --- b { font-weight: normal; }

      S 1 Reply Last reply
      0
      • S Skoder

        Hello, i didnt really know where to post this. Soo hope it is okay that i have posted it here. I hope that someone can help me with this regular expression which is giving me a lot of trouble. It should match +-:._ "space" a-z A-Z 0-9 in any given order or combination. There have to be at least one of the following characters a-z A-Z 0-9 though. Spaces are accepted but not as the start or end character. Also there can not be 2 spaces just after eachother. Right now i have the following regular expression which does all of it except there can be more than 1 spaces in a row: ^(?! )[ \+\.\-:\w]*(?=[a-zA-Z0-9]+)[ \+\.\-:\w]*(?

        M Offline
        M Offline
        Matt Gerrans
        wrote on last edited by
        #3

        Expresso - A Tool for Testing Regular Expressions[^] Matt Gerrans

        S 1 Reply Last reply
        0
        • G Guffa

          Handle the spaces as a complement to the characters. Each character (except the first) can optionally be preceded by a single space. ^[0-9A-Za-z0-9]( [\w+\-:\.])*$ Less is more. ;) --- b { font-weight: normal; }

          S Offline
          S Offline
          Skoder
          wrote on last edited by
          #4

          Hello, less might be more :-) but your regular expression seems to be incorrect. It only accepts if there is 1 space between each character, soo etc. "My Name" is not true, which it should be. Also it requires the first character to be 0-9 A-Z or a-z even though any character should be accepted. Spaces are allowed but not nessecary, as long as there is not 2 just after eachother or in the start or end. Also i think it might be a typo that there is 0-9 2 times in the first block ? and the + is not escaped ? It should be used for defining Usernames Anyway... any of the characters in any combination or order (At least one a-z A-Z 0-9 somewhere), as long as there is not 2 spaces directly after eachoter or spaces in the start or the end. "-: Whatever :-" <- true " wha e ver" <- false "My name ' ' is" <- false "My name is" <- true "__- What ever -__" <- true "A B C D E F G : + - _" <- true "_-: :-_" <- false (Should be at least 1x a-z A-Z or 0-9) "_-: T :-_" <- true Thanks for trying Martin -- modified at 14:18 Sunday 23rd October, 2005

          M G 2 Replies Last reply
          0
          • M Matt Gerrans

            Expresso - A Tool for Testing Regular Expressions[^] Matt Gerrans

            S Offline
            S Offline
            Skoder
            wrote on last edited by
            #5

            Hello, thanks for the reply. It looks good. Ill try it out. At the moment i am using - The Regex Coach Martin :)

            1 Reply Last reply
            0
            • S Skoder

              Hello, less might be more :-) but your regular expression seems to be incorrect. It only accepts if there is 1 space between each character, soo etc. "My Name" is not true, which it should be. Also it requires the first character to be 0-9 A-Z or a-z even though any character should be accepted. Spaces are allowed but not nessecary, as long as there is not 2 just after eachother or in the start or end. Also i think it might be a typo that there is 0-9 2 times in the first block ? and the + is not escaped ? It should be used for defining Usernames Anyway... any of the characters in any combination or order (At least one a-z A-Z 0-9 somewhere), as long as there is not 2 spaces directly after eachoter or spaces in the start or the end. "-: Whatever :-" <- true " wha e ver" <- false "My name ' ' is" <- false "My name is" <- true "__- What ever -__" <- true "A B C D E F G : + - _" <- true "_-: :-_" <- false (Should be at least 1x a-z A-Z or 0-9) "_-: T :-_" <- true Thanks for trying Martin -- modified at 14:18 Sunday 23rd October, 2005

              M Offline
              M Offline
              Matt Gerrans
              wrote on last edited by
              #6

              I can't blame Guffa; even after reading your original post and this reply, I still can't figure out exactly what you want. Maybe you should provide a list of user names that are acceptable and a separate list that are not. By the way, if your requirements for names are pretty standard, you can just google for "regular expression cookbook" or "user name regular expression" or the something similar and you will probably find what you are looking for. Matt Gerrans

              S 1 Reply Last reply
              0
              • M Matt Gerrans

                I can't blame Guffa; even after reading your original post and this reply, I still can't figure out exactly what you want. Maybe you should provide a list of user names that are acceptable and a separate list that are not. By the way, if your requirements for names are pretty standard, you can just google for "regular expression cookbook" or "user name regular expression" or the something similar and you will probably find what you are looking for. Matt Gerrans

                S Offline
                S Offline
                Skoder
                wrote on last edited by
                #7

                Hmmm... i cant really figure out how to describe it then. Characters that are accepted are a-z A-Z 0-9 and +-:_ and spaces ... The characters can be in any combination you can think of, as long as spaces are not the first or the last or 2 spaces just after eachother. Also at least 1 letter or number (a-zA-Z0-9) should present. Soo ... "::: - - :::" <- false because there is no letter or number in it "Hello # Hello" <- false because # is not allowed " Hello" <- false because first character is a space "Hello " <- false because last character is a space "Hello space space Hello" <- false 2 spaces just after eachother (space is = " " just cannot write it here) "My name is" <- true "_.-My Name Is-._" <- true "..... R ...." <- true Martin Characters: a-z A-Z 0-9 +-:_ Rules: A space " " cannot be the first or the last character. Also there cannot be a space directly after another space. At least one letter (a-zA-Z) or a number (0-9) should be in the string

                1 Reply Last reply
                0
                • S Skoder

                  Hello, less might be more :-) but your regular expression seems to be incorrect. It only accepts if there is 1 space between each character, soo etc. "My Name" is not true, which it should be. Also it requires the first character to be 0-9 A-Z or a-z even though any character should be accepted. Spaces are allowed but not nessecary, as long as there is not 2 just after eachother or in the start or end. Also i think it might be a typo that there is 0-9 2 times in the first block ? and the + is not escaped ? It should be used for defining Usernames Anyway... any of the characters in any combination or order (At least one a-z A-Z 0-9 somewhere), as long as there is not 2 spaces directly after eachoter or spaces in the start or the end. "-: Whatever :-" <- true " wha e ver" <- false "My name ' ' is" <- false "My name is" <- true "__- What ever -__" <- true "A B C D E F G : + - _" <- true "_-: :-_" <- false (Should be at least 1x a-z A-Z or 0-9) "_-: T :-_" <- true Thanks for trying Martin -- modified at 14:18 Sunday 23rd October, 2005

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

                  Yes, the regular expression I wrote is not correct. I forgot the ? after the space to make it optional, for one. So, forget the regular expression and just read what I said. --- b { font-weight: normal; }

                  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