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. Visual Basic
  4. Problem with regular expression

Problem with regular expression

Scheduled Pinned Locked Moved Visual Basic
helpregexalgorithmsjsonquestion
4 Posts 2 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
    shally_79
    wrote on last edited by
    #1

    Hi, i have to validate my password with this rules 1.i can enter any alpha numeric charcter 2.I can enter anything in a valid speical character set so i write my regular expression like this [a-zA-Z0-9 + strspecialCharacterString +] and to avoid special meaning of speical character i am adding \ in front of every special character.Now my problem in wen i use an _ in my pattern ie some thing like "*_<" it is not working.It throws an error below "parsing "[\*\_\<]" - Unrecognized escape sequence \_." if i give \\ instead of \ it is working.can any body help me in sorting out this problem? Thanks in advance shally

    sdf

    L 1 Reply Last reply
    0
    • S shally_79

      Hi, i have to validate my password with this rules 1.i can enter any alpha numeric charcter 2.I can enter anything in a valid speical character set so i write my regular expression like this [a-zA-Z0-9 + strspecialCharacterString +] and to avoid special meaning of speical character i am adding \ in front of every special character.Now my problem in wen i use an _ in my pattern ie some thing like "*_<" it is not working.It throws an error below "parsing "[\*\_\<]" - Unrecognized escape sequence \_." if i give \\ instead of \ it is working.can any body help me in sorting out this problem? Thanks in advance shally

      sdf

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, The underscore character is not a special character inside a regex, so it should NOT be escaped by a backslash; and when you prefix it by two backslashes, you are actually adding a single backslash to the list of acceptable characters. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      Fixturized forever. :confused:


      S 1 Reply Last reply
      0
      • L Luc Pattyn

        Hi, The underscore character is not a special character inside a regex, so it should NOT be escaped by a backslash; and when you prefix it by two backslashes, you are actually adding a single backslash to the list of acceptable characters. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        Fixturized forever. :confused:


        S Offline
        S Offline
        shally_79
        wrote on last edited by
        #3

        hi, Thanks a lot for your my answer.But i have one doubt.Why error is throwing only if we use underscore character."!,@,:" etc are not special character.But if i use them in my pattern no error is throwing. Why is it like this? Shally

        sdf

        L 1 Reply Last reply
        0
        • S shally_79

          hi, Thanks a lot for your my answer.But i have one doubt.Why error is throwing only if we use underscore character."!,@,:" etc are not special character.But if i use them in my pattern no error is throwing. Why is it like this? Shally

          sdf

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          These are the characters that have a special meaning in a regex expression: $ ^ { [ ( | ) * + ? \ If you need one of them literally, then you must escape it with a backslash; all other characters (including _ ! @ : ) are regular characters, just like a thru z and 0 thru 9. :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          Fixturized forever. :confused:


          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