Re: Regular Expression question
- From: "eBob.com" <fakename@xxxxxxxxxxxxxxxx>
- Date: Mon, 21 Sep 2009 20:17:57 -0400
Get Expresso from UltraPico (it's free!). It's an excellent tool for
experimenting with regualr expressions.
I think, THINK, that what you want to do is possible but I have never done
it.
I suspect you will need to use something called called a "backreference
construct". And a "grouping construct" - to "capture" what it is that you
need to backreference. At least that's how I'd approach it.
I'd begin by trying to match more than one of something, e.g. in "xx xx aa
yy yy yy bb" I'd try to find a pattern which would match the "xx" strings
and the "yy" strings.
Good Luck, Bob
"Jerry J" <JerryJ@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:5DDBCD98-3999-4D9C-8B96-F920D700204D@xxxxxxxxxxxxxxxx
Martin, thanks for the info, however, I realized I was not correct with my
example it should have looked like this:
I want to use the Regular Expressions MatchCollection to match multiple
patterns
in a string. I want to match the pattern that looks like "Word, Word".
Using the test code below I would want my match collection to contain
"Field1a Field1b, Field1c" and "Field3a, Field3b", but I can't get it to
work. Can
someone show me the pattern I need to use? Is it possible?
Dim sString As String = """Field1a Field1b, Field1c"", Field2, ""Field3a,
Field3b"",
Field4"
Dim sPattern As String = """[\S ]*,[\S ]*"""
Dim reg_exp As New Regex(sPattern)
Dim matches As MatchCollection = reg_exp.Matches(sString)
--
Jerry J
"Martin Honnen" wrote:
Jerry J wrote:
I want to use the Regular Expressions MatchCollection to match multiple
patterns
in a string. I want to match the pattern that looks like "Word, Word".
Using the test code below I would want my match collection to contain
"Field1a, Field1b" and "Field3a, Field3b", but I can't get it to work.
Can
someone show me the pattern I need to use?
Dim sString As String = """Field1a, Field1b"", Field2, ""Field3a,
Field3b"",
Field4"
Dim sPattern As String = """[\S ]*,[\S ]*"""
Dim reg_exp As New Regex(sPattern)
Dim matches As MatchCollection = reg_exp.Matches(sString)
Dim sString As String = """Field1a, Field1b"", Field2,
""Field3a, Field3b"", Field4("")"
Dim matches As MatchCollection = _
Regex.Matches(sString, "(""(\w+)\w*, (\2)\w*"")")
For Each m As Match In matches
Console.WriteLine(m.Value)
Next
--
Martin Honnen --- MVP XML
http://msmvps.com/blogs/martin_honnen/
.
- References:
- Regular Expression question
- From: Jerry J
- Re: Regular Expression question
- From: Martin Honnen
- Re: Regular Expression question
- From: Jerry J
- Regular Expression question
- Prev by Date: Re: Toolbox disabled in vb2008
- Next by Date: Re: Regular Expression question
- Previous by thread: Re: Regular Expression question
- Next by thread: Re: Regular Expression question
- Index(es):
Relevant Pages
|