473,378 Members | 1,467 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,378 software developers and data experts.

Storing regular expressions in string variables

VS magazine 11 04 shows how to use regular expression fro parsing text file.
I have problem storing the following expression in a string variable:
^\s*(<q1>("|'))(?<firstname>.*)\k<q1>\s*$

the single quote (') turns the rest of the string into an in line comment!
Can you please how to handle this?
Thanks
Bill

Nov 21 '05 #1
7 1866
Are you trying to do this?

Dim S as string
S = "^\s*(<q1>(""|'))(?<firstname>.*)\k<q1>\s*$"

Chris

"Bill Nguyen" <bi*****************@jaco.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
VS magazine 11 04 shows how to use regular expression fro parsing text
file.
I have problem storing the following expression in a string variable:
^\s*(<q1>("|'))(?<firstname>.*)\k<q1>\s*$

the single quote (') turns the rest of the string into an in line comment!
Can you please how to handle this?
Thanks
Bill

Nov 21 '05 #2
"Bill Nguyen" <bi*****************@jaco.com> schrieb:
VS magazine 11 04 shows how to use regular expression fro parsing text
file.
I have problem storing the following expression in a string variable:
^\s*(<q1>("|'))(?<firstname>.*)\k<q1>\s*$

the single quote (') turns the rest of the string into an in line comment!


Replace all double quote characters inside the string literal with two
successive double quotes.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #3
Errata:

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> schrieb:
Replace all double quote characters inside the string literal with two
successive double quotes.


"successive" -> "consecutive".

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #4
This seemed to work, however, it doesn't solve the problem of removing the
quotes around the field values.
I tried to use string.Replace to change double quotes (") to single quote
(') but double quotes gain gave me problem.
for example, I want to change "Value 1" to 'Value 1'
What's the chr() value for single quote and double quotes in VB.NET?
Thanks
Bill
"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com> wrote
in message news:uB**************@TK2MSFTNGP09.phx.gbl...
Are you trying to do this?

Dim S as string
S = "^\s*(<q1>(""|'))(?<firstname>.*)\k<q1>\s*$"

Chris

"Bill Nguyen" <bi*****************@jaco.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
VS magazine 11 04 shows how to use regular expression fro parsing text
file.
I have problem storing the following expression in a string variable:
^\s*(<q1>("|'))(?<firstname>.*)\k<q1>\s*$

the single quote (') turns the rest of the string into an in line comment! Can you please how to handle this?
Thanks
Bill


Nov 21 '05 #5
If I understand your problem you have this:

//Not tested
Dim S As String
S = ""Value 1"" ' Now S equals "Value 1"
S = S.Replace(""", "'")
messagebox.show(S) 'Now S equals 'Value 1'

Does that help?
Chris

"Bill Nguyen" <bi*****************@jaco.com> wrote in message
news:uD**************@TK2MSFTNGP11.phx.gbl...
This seemed to work, however, it doesn't solve the problem of removing the
quotes around the field values.
I tried to use string.Replace to change double quotes (") to single quote
(') but double quotes gain gave me problem.
for example, I want to change "Value 1" to 'Value 1'
What's the chr() value for single quote and double quotes in VB.NET?
Thanks
Bill
"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com>
wrote
in message news:uB**************@TK2MSFTNGP09.phx.gbl...
Are you trying to do this?

Dim S as string
S = "^\s*(<q1>(""|'))(?<firstname>.*)\k<q1>\s*$"

Chris

"Bill Nguyen" <bi*****************@jaco.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
> VS magazine 11 04 shows how to use regular expression fro parsing text
> file.
> I have problem storing the following expression in a string variable:
> ^\s*(<q1>("|'))(?<firstname>.*)\k<q1>\s*$
>
> the single quote (') turns the rest of the string into an in line comment! > Can you please how to handle this?
> Thanks
> Bill
>
>
>



Nov 21 '05 #6
Chris;

I had to use chr(34) in lieu of """.
S = S.Replace(""", "'") -> not working
S = S.Replace(chr(34), "'") -> working.

Thanks for your help.
Bill

"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com> wrote
in message news:%2****************@TK2MSFTNGP14.phx.gbl...
If I understand your problem you have this:

//Not tested
Dim S As String
S = ""Value 1"" ' Now S equals "Value 1"
S = S.Replace(""", "'")
messagebox.show(S) 'Now S equals 'Value 1'

Does that help?
Chris

"Bill Nguyen" <bi*****************@jaco.com> wrote in message
news:uD**************@TK2MSFTNGP11.phx.gbl...
This seemed to work, however, it doesn't solve the problem of removing the quotes around the field values.
I tried to use string.Replace to change double quotes (") to single quote (') but double quotes gain gave me problem.
for example, I want to change "Value 1" to 'Value 1'
What's the chr() value for single quote and double quotes in VB.NET?
Thanks
Bill
"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com>
wrote
in message news:uB**************@TK2MSFTNGP09.phx.gbl...
Are you trying to do this?

Dim S as string
S = "^\s*(<q1>(""|'))(?<firstname>.*)\k<q1>\s*$"

Chris

"Bill Nguyen" <bi*****************@jaco.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
> VS magazine 11 04 shows how to use regular expression fro parsing text > file.
> I have problem storing the following expression in a string variable:
> ^\s*(<q1>("|'))(?<firstname>.*)\k<q1>\s*$
>
> the single quote (') turns the rest of the string into an in line

comment!
> Can you please how to handle this?
> Thanks
> Bill
>
>
>



Nov 21 '05 #7
"Bill Nguyen" <bi*****************@jaco.com> schrieb:
I had to use chr(34) in lieu of """.
S = S.Replace(""", "'") -> not working


Please read the answers other people give you! Every double quote is
encoded as /two/ consecutive double quotes.

\\\
s = s.Replace(""""c, "'"c)
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #8

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

Similar topics

1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
5
by: Drew | last post by:
We have a string like: 2004\05\05T00:00:00 We would like to remove all "\", any "-" and the T00:00:00 part of the string. The end result would be 20040505. I know that if I use as the...
2
by: ajitgoel | last post by:
Hi; I need some simple help with my regular expressions. I want to search my input text for all the boolean variables which do not start with bln. i.e I want to match "bool followed by 1 or...
2
by: Sehboo | last post by:
Hi, I have several regular expressions that I need to run against documents. Is it possible to combine several expressions in one expression in Regex object. So that it is faster, or will I...
7
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
2
by: comp.lang.php | last post by:
I am trying to replace within the HTML string $html the following: With Where I'm replacing "action=move_image" with "action=<?= $_REQUEST ?>"
34
by: Antoine De Groote | last post by:
Hello, Can anybody tell me the reason(s) why regular expressions are not built into Python like it is the case with Ruby and I believe Perl? Like for example in the following Ruby code line =...
1
by: Allan Ebdrup | last post by:
I have a dynamic list of regular expressions, the expressions don't change very often but they can change. And I have a single string that I want to match the regular expressions against and find...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

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.