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 Help!

Regular Expression Help!

Scheduled Pinned Locked Moved C#
regexhelp
5 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.
  • D Offline
    D Offline
    dturton
    wrote on last edited by
    #1

    Can someone please give me a regular expression that I can use with the split() method to delimit the a string such as the one that follows into 20 separate fields. It is comma-quote delimited, however nulls are not quoted (,,) and it is possible to have commas inside a quoted value ("1,2,7,7,8-PECDD"). Thanks...David "42679","A106037#2","-9999","BL0414WJ","BL0414WJLB1","Laboratory Blank","DIOXINS/FURANS (GHK)","04/14/2000","04/19/2000","pg/l","1,2,7,7,8-PECDD","40321-76-4","6.016","6.016","U",,,"NO","YES" David

    D 1 Reply Last reply
    0
    • D dturton

      Can someone please give me a regular expression that I can use with the split() method to delimit the a string such as the one that follows into 20 separate fields. It is comma-quote delimited, however nulls are not quoted (,,) and it is possible to have commas inside a quoted value ("1,2,7,7,8-PECDD"). Thanks...David "42679","A106037#2","-9999","BL0414WJ","BL0414WJLB1","Laboratory Blank","DIOXINS/FURANS (GHK)","04/14/2000","04/19/2000","pg/l","1,2,7,7,8-PECDD","40321-76-4","6.016","6.016","U",,,"NO","YES" David

      D Offline
      D Offline
      Daniel Turini
      wrote on last edited by
      #2

      ,?"(?<value>.*?)"|,?(?<value>.*?) This will let you extract the values as named groups, but will not work as a split separator. I see dumb people

      S 1 Reply Last reply
      0
      • D Daniel Turini

        ,?"(?<value>.*?)"|,?(?<value>.*?) This will let you extract the values as named groups, but will not work as a split separator. I see dumb people

        S Offline
        S Offline
        Stephane Rodriguez
        wrote on last edited by
        #3

        Daniel Turini wrote: ,?"(?.*?)"|,?(?.*?) I have just added CodeProject support to your regexp : ,?"(?.*?)"|,?(? :confused: .*?)

        D 1 Reply Last reply
        0
        • S Stephane Rodriguez

          Daniel Turini wrote: ,?"(?.*?)"|,?(?.*?) I have just added CodeProject support to your regexp : ,?"(?.*?)"|,?(? :confused: .*?)

          D Offline
          D Offline
          Daniel Turini
          wrote on last edited by
          #4

          Oh, I just love regex, it's an art form. Here's a regex which can validate (it's not mine, I found it on the web): 1. All valid dates from 1/1/0001 to 31/12/9999 2. Correctly validates leap years 3. It's valid for the regex classes on .NET framework ^(?: (?: (?:0?[13578]|1[02])(\/|-)31)|(?: (?:0?[1,3-9]|1[0-2])(\/|-)(?:29|30)))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^(?: (?:0?[1-9]|1[0-2])(\/|-)(?:0?[1-9]|1\d|2[0-8]))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^(0?2(\/|-)29)(\/|-)(?: (?:0[48]00|[13579][26]00|[2468][048]00)|(?:\d\d)?(?:0[48]|[2468][048]|[13579][26]))$ Remove all the spaces from it, I've added some to bypass the emoticons. I see dumb people

          S 1 Reply Last reply
          0
          • D Daniel Turini

            Oh, I just love regex, it's an art form. Here's a regex which can validate (it's not mine, I found it on the web): 1. All valid dates from 1/1/0001 to 31/12/9999 2. Correctly validates leap years 3. It's valid for the regex classes on .NET framework ^(?: (?: (?:0?[13578]|1[02])(\/|-)31)|(?: (?:0?[1,3-9]|1[0-2])(\/|-)(?:29|30)))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^(?: (?:0?[1-9]|1[0-2])(\/|-)(?:0?[1-9]|1\d|2[0-8]))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^(0?2(\/|-)29)(\/|-)(?: (?:0[48]00|[13579][26]00|[2468][048]00)|(?:\d\d)?(?:0[48]|[2468][048]|[13579][26]))$ Remove all the spaces from it, I've added some to bypass the emoticons. I see dumb people

            S Offline
            S Offline
            Stephane Rodriguez
            wrote on last edited by
            #5

            Who needs MSIL obfuscation when you've got RegExp. Of course, the trouble is you obfuscate your code to yourself :laugh:

            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