Re: Regular Expression help needed

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




> James Whitlow wrote:
>
> > I am not sure if this is exactly what you are looking for, but it seems to
> > work with my 6 variations.
> >
> > '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > Dim oRegEx, arrTest(5), sLine
> > Set oRegEx = CreateObject("VBScript.RegExp")
> >
> > oRegEx.Pattern = "^.*(?:\b|\\P)([A-D]{1}\d{6})(?:\b|\\P).*$"
> >
> > arrTest(0) = "This is a \PA123456 test line..."
> > arrTest(1) = "%89434\PB254689\P~1@3df"
> > arrTest(2) = "%89434 D787689 ~1@3df"
> > arrTest(3) = "This is a \PA123456\P test line..."
> > arrTest(4) = "This is a \PA123456 \Ptest line..."
> > arrTest(5) = "%89434 C711689\P~1@3df"
> >
> > For Each sLine in arrTest
> > MsgBox oRegEx.Replace(sLine, "$1")
> > Next
> > '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> Your test cases seem to cover the cases I expect. I will have to study
> your pattern. There are things in it I've never seen before.
>
> thank you
> LJB

Its interesting how \\P captures those characters as well as the rest
of the pattern yet \b does not capture its character. Is there a way to
specify a character in the pattern but not capture it using it only to
mark the beginning or end? Since I'm not interested in capturing \P I
think I'll regexp.replace it with a space and go back to using my old
pattern.

thanks
LJB

.



Relevant Pages

  • Re: Regular Expression help needed
    ... Is there a way to specify a character in the pattern but not capture it using it only to mark the beginning or end? ...
    (microsoft.public.scripting.vbscript)
  • Re: Regular Expression help needed
    ... > specify a character in the pattern but not capture it using it only to ... Dim oRegEx, arrTest, sLine ...
    (microsoft.public.scripting.vbscript)
  • Re: RegEx: How to ignore the number of whitespaces?
    ... a "simpler" regular expression syntax is likely to bite you eventually, ... but that some of these character sequences may be "marked" as ... This is a regular expression "if" conditional statement, ... do not understand why the pattern "personal computer" will only match ...
    (microsoft.public.dotnet.framework)
  • Re: "String" manipulation for a Case clause
    ... ' Dim objRegExp As RegExp ... I would use Double or String. ... 'non-word character. ... 'construct a pattern like: ...
    (microsoft.public.excel.programming)
  • Re: empty displayed data except "space" and "newline"
    ... You don't need to remove spaces to put words into an array. ... .....Although you may want a different pattern than I use, ... upon your definition of "empty character". ... You said that that code is "For identifying whether it's an 'empty ...
    (perl.beginners)