Re: Regular Expression question

Tech-Archive recommends: Fix windows errors by optimizing your registry



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/



.



Relevant Pages

  • Re: Regular Expression question
    ... Martin, thanks for the info, however, I realized I was not correct with my ... I want to use the Regular Expressions MatchCollection to match multiple ... I want to match the pattern that looks like "Word, ... Dim matches As MatchCollection = reg_exp.Matches ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Regular Expression question
    ... I want to match the pattern that looks like "Word, ... Using the test code below I would want my match collection to contain ... Dim matches As MatchCollection = reg_exp.Matches ...
    (microsoft.public.dotnet.languages.vb)
  • Re: [SLE] Postfix - Sandy - 1 more Q re: /etc/postfix/recepient_check
    ... I'm a little hesitant to answer, because I'm not sure what "regular" means in this case. ... Regular expressions are an absolute must for adminstrators. ... You will encounter these pattern matching expressions in most scripting and programming languages. ... Additionally it will use the content in the round brackets as $1, $2 (content of first found expression in brackets, second found... ...
    (SuSE)
  • Re: HOF implementation of "until"
    ... "Patterns appear in lambda abstractions, function definitions, pattern bindings, list ... comprehensions, do expressions, and case ... as described in figures 3.1 and 3.2 from the Haskell report. ...
    (comp.lang.functional)
  • Re: Regular Expression question
    ... I want to use the Regular Expressions MatchCollection to match multiple ... I want to match the pattern that looks like "Word, ... Quantifiers in regex are gready by default - in other words, ... to tell the regex engine to not be gready, ...
    (microsoft.public.dotnet.languages.vb)