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

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 1750
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Julie | last post by:
I'm an admitted regex moron, but I need help w/ an expression for parsing. Here is the input string: (123.45)ABC(44.55) with a regex expression of \(|\)
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...
17
by: clintonG | last post by:
I'm using an .aspx tool I found at but as nice as the interface is I think I need to consider using others. Some can generate C# I understand. Your preferences please... <%= Clinton Gallagher ...
7
by: lgbjr | last post by:
Hi All, I'm trying to split a string on every character. The string happens to be a representation of a hex number. So, my regex expression is (). Seems simple, but for some reason, I'm not...
4
by: MooMaster | last post by:
I'm trying to develop a little script that does some string manipulation. I have some few hundred strings that currently look like this: cond(a,b,c) and I want them to look like this: ...
7
by: Jordi Rico | last post by:
Hi, I know I can split a string into an array doing this: Dim s As String()=Regex.Split("One-Two-Three","-") So I would have: s(0)="One" s(1)="Two"
10
by: bullockbefriending bard | last post by:
first, regex part: I am new to regexes and have come up with the following expression: ((1|),(1|)/){5}(1|),(1|) to exactly match strings which look like this: 1,2/3,4/5,6/7,8/9,10/11,12 ...
3
by: ommail | last post by:
Hi I wonder if regular expressions are in general sower than using classes like String and Char when used for validating/parsing text data? I've done some simple test (using IsMatch()) method...
7
by: =?Utf-8?B?amFj?= | last post by:
Hi, I have problems with following code and don’t find the bug : // Set ArrayList aArray = new ArrayList(); regStr = new Regex(@"\?)*(\d+)\]"); if(text != null && regStr.IsMatch(text))...
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.