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_EXP

REGULAR_EXP

Scheduled Pinned Locked Moved C#
question
2 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.
  • B Offline
    B Offline
    Bedevian
    wrote on last edited by
    #1

    this code let me write optional 4 digits and 3 decimal 1234.000 const string REGULAR_EXP = "(^-?\\d{1,4}\\.$)|(^-?\\d{1,4}$)|(^-?\\d{0,4}\\.\\d{1,3}$)"; i don't understand why if i type a number for ex. 12 and then add a minus (-) in front it works, but it doesn't if you type first minus (-) and then the number. i want REGULAR_EXP to add optional minus (-) before u type a number

    C 1 Reply Last reply
    0
    • B Bedevian

      this code let me write optional 4 digits and 3 decimal 1234.000 const string REGULAR_EXP = "(^-?\\d{1,4}\\.$)|(^-?\\d{1,4}$)|(^-?\\d{0,4}\\.\\d{1,3}$)"; i don't understand why if i type a number for ex. 12 and then add a minus (-) in front it works, but it doesn't if you type first minus (-) and then the number. i want REGULAR_EXP to add optional minus (-) before u type a number

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      If you put an @ at the beginning of your string, you won't need to \\ your \'s, which makes the regex more readable. This doesn't always match what you'd hope, if you enter 3444.223, it will match the 3444. because that's the first test that works. You should change this to be all one regex, instead of three. However, the - part work fine for me in expresso. Your regex is working, what you need to explain is in what context you feel it does not work if you type the minus first. Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer

      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