Regular Expression
-
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.
((?[^\",\\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.
-
((?[^\",\\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.