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 expression format

Regular expression format

Scheduled Pinned Locked Moved C#
regexcsharpquestion
6 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
    chandler83
    wrote on last edited by
    #1

    Hi can u please let me know wht the following format means also please give me some examples for this.... Regex re=new Regex("^([0-9]+d )?([0-9]+h )?([0-9]+m )?([0-9]+s )?$"); regular expression in c#. thanks in advance.....

    C L 2 Replies Last reply
    0
    • C chandler83

      Hi can u please let me know wht the following format means also please give me some examples for this.... Regex re=new Regex("^([0-9]+d )?([0-9]+h )?([0-9]+m )?([0-9]+s )?$"); regular expression in c#. thanks in advance.....

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

      chandler83 wrote:

      ([0-9]+d )?([

      Any number of digits, followed by a lowercase d. The ? means this group doesn't have to exist for there to be a match next group does the same for digits followed by h, then the same with m, then the same with s. I believe that ^ means the start of a line, and $ means the end. This will match an empty line, or a line that matches any one of those groups. If there's only ever one group, and it could contain d/h/m or s after the numbers, then the better way to write it would be Regex re=new Regex("^([0-9]+[dhms])$"); This also won't match an empty string. The brackets control grouping, groups that matched can be retrieved after performing a regex.

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

      L C 2 Replies Last reply
      0
      • C Christian Graus

        chandler83 wrote:

        ([0-9]+d )?([

        Any number of digits, followed by a lowercase d. The ? means this group doesn't have to exist for there to be a match next group does the same for digits followed by h, then the same with m, then the same with s. I believe that ^ means the start of a line, and $ means the end. This will match an empty line, or a line that matches any one of those groups. If there's only ever one group, and it could contain d/h/m or s after the numbers, then the better way to write it would be Regex re=new Regex("^([0-9]+[dhms])$"); This also won't match an empty string. The brackets control grouping, groups that matched can be retrieved after performing a regex.

        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Christian Graus wrote:

        Regex re=new Regex("^([0-9]+[dhms])$");

        Wrong. What you probably meant was ^([0-9]+[dhms]){0,4}$ But that would still be wrong, because it wouldn't preserve the order of d,h,m,s. The original Regex at least ensures the correct order of d, then h, then m, then s.

        Christian Graus wrote:

        Any number of digits

        Just to not confuse the thread opener: it acutually meast at least one digit + = one or more * = zero or more ? = optional character, group regards

        C 1 Reply Last reply
        0
        • C chandler83

          Hi can u please let me know wht the following format means also please give me some examples for this.... Regex re=new Regex("^([0-9]+d )?([0-9]+h )?([0-9]+m )?([0-9]+s )?$"); regular expression in c#. thanks in advance.....

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          In addition to what Christian already said, here's some examples: 123d542m 32d167h764m317s 7s Even an empty line would match, because all this occurances are optional (hence the ?) regards

          1 Reply Last reply
          0
          • C Christian Graus

            chandler83 wrote:

            ([0-9]+d )?([

            Any number of digits, followed by a lowercase d. The ? means this group doesn't have to exist for there to be a match next group does the same for digits followed by h, then the same with m, then the same with s. I believe that ^ means the start of a line, and $ means the end. This will match an empty line, or a line that matches any one of those groups. If there's only ever one group, and it could contain d/h/m or s after the numbers, then the better way to write it would be Regex re=new Regex("^([0-9]+[dhms])$"); This also won't match an empty string. The brackets control grouping, groups that matched can be retrieved after performing a regex.

            Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

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

            thts perfect........ thank u very much Christian Graus...

            1 Reply Last reply
            0
            • L Lost User

              Christian Graus wrote:

              Regex re=new Regex("^([0-9]+[dhms])$");

              Wrong. What you probably meant was ^([0-9]+[dhms]){0,4}$ But that would still be wrong, because it wouldn't preserve the order of d,h,m,s. The original Regex at least ensures the correct order of d, then h, then m, then s.

              Christian Graus wrote:

              Any number of digits

              Just to not confuse the thread opener: it acutually meast at least one digit + = one or more * = zero or more ? = optional character, group regards

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

              Greeeg wrote:

              Wrong. What you probably meant was ^([0-9]+[dhms]){0,4}$

              No, you're wrong. I said if the regex is intending to find ONLY ONE group out of the four ( not any of the four groups, in that order ), then the regex I provided would be a substitute.

              Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

              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