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. Web Development
  3. ASP.NET
  4. Regular Expression

Regular Expression

Scheduled Pinned Locked Moved ASP.NET
regexquestion
3 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.
  • V Offline
    V Offline
    VK Cadec
    wrote on last edited by
    #1

    Hi, Does anyone know what this following regular expression would interpret as? Regex re=new Regex("((?[^\",\\r\\n]*)|\"(?([^\"]|\"\")*)\")(,|(?\\r\\n|\\n|$))"); Many thanks for your time.

    E 1 Reply Last reply
    0
    • V VK Cadec

      Hi, Does anyone know what this following regular expression would interpret as? Regex re=new Regex("((?[^\",\\r\\n]*)|\"(?([^\"]|\"\")*)\")(,|(?\\r\\n|\\n|$))"); Many thanks for your time.

      E Offline
      E Offline
      Ed Poore
      wrote on last edited by
      #2

      ((?[^\",\\r\\n]*)|\"(?([^\"]|\"\")*)\")(,|(?\\r\\n|\\n|$)) Basically (...)s create a group which can be retrieved later from the results if it has a (?...) then it is simply used as grouping in the regex and is not output to the results. Pattern 1: The 1st bracket then is looking any characters bar for a quote (") followed by a comma (,) and carriage return / line feed (\r\n).  It wants one or more of these consecutively. Pattern 2: The 2nd bracket is looking for any characters except a quote or a two quotes, again matching zero or more of these consecutively. Pattern 3: The 3rd bracket(s) are looking for a comma or (a carriage return, line feed or a new line or the end of the string). So in summary it's matching Pattern 1 or a quote followed by Pattern 2 and 3. Hope that explains it a bit, it's quite difficult to put into words, just remember that brackets act like grouping constructs like in any programming language, except here unless they have a ? following the opening parenthesis (? then the group is output into the results.


      My Blog

      V 1 Reply Last reply
      0
      • E Ed Poore

        ((?[^\",\\r\\n]*)|\"(?([^\"]|\"\")*)\")(,|(?\\r\\n|\\n|$)) Basically (...)s create a group which can be retrieved later from the results if it has a (?...) then it is simply used as grouping in the regex and is not output to the results. Pattern 1: The 1st bracket then is looking any characters bar for a quote (") followed by a comma (,) and carriage return / line feed (\r\n).  It wants one or more of these consecutively. Pattern 2: The 2nd bracket is looking for any characters except a quote or a two quotes, again matching zero or more of these consecutively. Pattern 3: The 3rd bracket(s) are looking for a comma or (a carriage return, line feed or a new line or the end of the string). So in summary it's matching Pattern 1 or a quote followed by Pattern 2 and 3. Hope that explains it a bit, it's quite difficult to put into words, just remember that brackets act like grouping constructs like in any programming language, except here unless they have a ? following the opening parenthesis (? then the group is output into the results.


        My Blog

        V Offline
        V Offline
        VK Cadec
        wrote on last edited by
        #3

        It is comma delimited csv file that is being read. To change the comma to a tilda(~) delimited file, would changing in those two places a comma occurs to tilda work? Thanks.

        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