By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,290 Members | 1,666 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,290 IT Pros & Developers. It's quick & easy.

Regex Expression to split on a quote

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
Peter,

Good catch,

:-)

Cor
Nov 21 '05 #4

P: n/a
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

P: n/a
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.