469,156 Members | 2,202 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,156 developers. It's quick & easy.

Regex Expression to split on a quote

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 I can't figure out how to
escape a quote. The closest I got was Regex.split(String,"(\"")"), which
gives me an array of strings:

"X:Y\Z.exe
"
"123

I thought that using (\") would be what I needed (escaping a single quote),
but that produces a syntax error.

Can someone tell me the correct syntax for a Regex expression to split on a
quote. Or, if there's a better way to do this, I'm open to suggestions.

TIA,

Lee
Nov 21 '05 #1
5 1569
lgbjr,

This link is from every dotnet newsgroup by a lot of people advices to use
Expresso
http://www.ultrapico.com/Expresso.htm

I hope this helps a little bit?

Cor
Nov 21 '05 #2
Hi

In VB syntax, the "" is the escape character for ".

Here is a module for your reference.
Module Module1
Sub Main()
Dim str As String = "asdfsadf""fasdfasdf""fasdfasdf"
Dim strs() As String = Split(str, """")
For Each s As String In strs
Console.WriteLine(s)
Next
End Sub
End Module
Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #3
Peter,

Good catch,

:-)

Cor
Nov 21 '05 #4
Great Tool! Thanks for the link!

"Cor Ligthert" <no************@planet.nl> wrote in message
news:Oz**************@TK2MSFTNGP09.phx.gbl...
lgbjr,

This link is from every dotnet newsgroup by a lot of people advices to use
Expresso
http://www.ultrapico.com/Expresso.htm

I hope this helps a little bit?

Cor

Nov 21 '05 #5
Lee,
What are you expecting as output?

Reading "within each set of quotes" it sounds like you expect a 2 element
array with:

(0) = "X:Y\Z.exe"
(1) = "123"

I would use a pattern such as "(?<value>.*?)" (including quotes), and use a
loop to find each match.

Something like:

Dim input As String = """X:Y\Z.exe"" ""123"""
Dim pattern As String = """(?<value>.*?)"""
Static parser As New System.Text.RegularExpressions.Regex(pattern,
RegularExpressions.RegexOptions.Compiled)

Dim list As New ArrayList

Dim match As match = parser.Match(input)
Do While match.Success
list.Add(match.Groups("value").Value)
match = match.NextMatch()
Loop
Expresso & RegEx Workbench both have wizards of varying degrees to help you
build your expression, plus they allow you to test your expressions, also
the analyzer/interpreter in each is rather handy.

Expresso:
http://www.ultrapico.com/Expresso.htm

RegEx Workbench:
http://www.gotdotnet.com/Community/U...-4ee2729d7322A

tutorial & reference on using regular expressions:
http://www.regular-expressions.info/

The MSDN's documentation on regular expressions:
http://msdn.microsoft.com/library/de...geElements.asp

Hope this helps
Jay


"lgbjr" <lg***@online.nospam> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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 I can't figure out
how to escape a quote. The closest I got was Regex.split(String,"(\"")"),
which gives me an array of strings:

"X:Y\Z.exe
"
"123

I thought that using (\") would be what I needed (escaping a single
quote), but that produces a syntax error.

Can someone tell me the correct syntax for a Regex expression to split on
a quote. Or, if there's a better way to do this, I'm open to suggestions.

TIA,

Lee

Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Julie | last post: by
17 posts views Thread by clintonG | last post: by
7 posts views Thread by lgbjr | last post: by
4 posts views Thread by MooMaster | last post: by
7 posts views Thread by Jordi Rico | last post: by
10 posts views Thread by bullockbefriending bard | last post: by
7 posts views Thread by =?Utf-8?B?amFj?= | last post: by
1 post views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.