escaping double quotes in Regex

G

Guest

Hi All

How do you escape a double quote in a Regex? I am having problems with, what should be, a simple regular expression statement. I have a string like (including leading spaces (but thats not my problem))

web_url("ForEx"

and, using the regex

Dim RE_WebURLName As Regex = New Regex(" *web_url\((?<WebURLName>.*),"

I have no problem capturing

"ForEx

The problem is that I want to capture

ForE

that is, I want the string without the enclosing double quotes

I've tried

Dim RE_WebURLName As Regex = New Regex(" *web_url\(\"(?<WebURLName>.*)\","

an

Dim RE_WebURLName As Regex = New Regex(" *web_url\("(?<WebURLName>.*)","

but, in both cases, I get something like this when compiling

error BC30037: Character is not valid
Dim RE_WebURLName As Regex = New Regex(" *web_url\(\"(?<WebURLName>.*)\","

(the tilde is under the '?'

It seems like escaping prior to the double quote is having no effect. What am I doing wrong

Thank
Martin
 
G

Guest

Double the double quotes to escape them

Dim RE_WebURLName As Regex = New Regex(" *web_url\(""(?<WebURLName>.*)"","
 
B

Brian Davis

Doubling the double-quote is required by VB syntax, not Regex syntax. To
put a double-quote in any String literal in VB (like a Regex pattern), you
must double it; otherwise it looks like the end of the String.


Brian Davis
http://www.knowdotnet.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top