473,241 Members | 1,508 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,241 software developers and data experts.

Regex String searching for quotes

bob
Hi
I have a long regex string that needs to match the quote char. It is
matching a CSV text file where all data fields are encased in quotes.
Some fields are empty ie double quotes. I want to make sure all fields
are correctly formed.
Is there any easy way to embed the '"" in the string or do I have to
break it up into something like
char quote = '"';
string myregex = "\\A" +quote + ",([^,\r\n]*)" + quote + "," + quote
+",([^,\r\n]*)" etc etc.
I formed the regex string in RegexBuddy and would love to just dump
into a c# string
thanks
Bob
Jul 11 '07 #1
3 3672
You just need to escape it correctly... I think you need to read up on
string escaping (in both forms) - see http://msdn2.microsoft.com/en-us/lib...fe(VS.80).aspx

Another option (especially useful for regex) is to make use of a
resource file; this allows you to store (named) strings, but without
any escaping at all - which will allow you to paste the regex verbatim
into the designer. You can then access this string at runtime via (for
instance) Resources.MyRegex.

Marc

Jul 11 '07 #2
bob wrote:
Hi
I have a long regex string that needs to match the quote char. It is
matching a CSV text file where all data fields are encased in quotes.
Some fields are empty ie double quotes. I want to make sure all fields
are correctly formed.
Is there any easy way to embed the '"" in the string or do I have to
break it up into something like
char quote = '"';
string myregex = "\\A" +quote + ",([^,\r\n]*)" + quote + "," + quote
+",([^,\r\n]*)" etc etc.
I formed the regex string in RegexBuddy and would love to just dump
into a c# string
thanks
Bob
You can use \" to put a quote in a string. You also have to escape the
backslash into \\.

A convenient string format for regular expression patterns is the @
delimited string. That turns off all escape sequences, and you use
double quotes to put a quote in the string:

string myregex = @"\\A"",([^,\r\n]*)"","",([^,\r\n]*)";

--
Göran Andersson
_____
http://www.guffa.com
Jul 11 '07 #3
bob
Marc and Goran,
Thank you.
I went with the string literal.
regards
Bob
Jul 11 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jon Maz | last post by:
Hi All, Am getting frustrated trying to port the following (pretty simple) function to CSharp. The problem is that I'm lousy at Regular Expressions.... //from...
4
by: William Stacey [MVP] | last post by:
Would like help with a (I think) a common regex split example. Thanks for your example in advance. Cheers! Source Data Example: one "two three" four Optional, but would also like to...
6
by: Dave | last post by:
I'm struggling with something that should be fairly simple. I just don't know the regext syntax very well, unfortunately. I'd like to parse words out of what is basically a boolean search...
3
by: Luis Esteban Valencia | last post by:
hello quite a simple one if you understand regular expressions vbscript and ..net, probably quite hard if you don't i have a single line input which offers classic search functionality, so if...
5
by: lgbjr | last post by:
Hello All, I have the following type of string: "X:Y\Z.exe" "123" What I need is an array of strings with the information from within each set of quotes. I was trying to use a Regex.Split, but...
4
by: JS | last post by:
I am writing a C# app that needs to parse a sentence entered by the user for a simple boolean search. I need to capture all of the AND words that are not inside of double quotes. However, I am...
8
by: Bob | last post by:
I need to create a Regex to extract all strings (including quotations) from a C# or C++ source file. After being unsuccessful myself, I found this sample on the internet: ...
9
by: jmchadha | last post by:
I have got the following html: "something in html ... etc.. city1... etc... <a class="font1" href="city1.html" onclick="etc."click for <b>info</bon city1 </a> ... some html. city1.. can repeat...
2
by: Neeta | last post by:
Hi All, I am having problem using Regex.Replace.I am trying to search all the strings present in a .cs file and replace it with a different string .I am doing this by searching all the code...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.