Re: RegEx

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



Steve,
Boy, you are really a genius at this. Do you work with RegEx a lot or are
you just plain brilliant?
Thanks for the help.
Regards
HS

"Steve Fulton" <cerberus40@xxxxxxxxxxx> wrote in message
news:op.s569mvb8i0ix9l@xxxxxxxx
HSalim[MVP] wrote:

I wanted to add support for table names enclosed in square brackets, and
added my comments.
This works for me but if there is a more compact definition, I'd love to
learn from it .
An updated definition and a test text string are pasted below if you want
to
test it.

If you can absolutely, positively, 100% guarantee that every table name
that starts with a "[" ends with a "]", you can define each table name
as "\[?\w+\]?". If there is *any* possibility, no matter how small,
that this is not the case, you need to test for each case separately,
as you do now.

However, your current pattern will match only cases where all the table
names are in brackets or none of them are. If you have a table name in
the form "[name1].name2.[name3]", your pattern will not find all of it
(it will match "[name1]").

Here is a more compact pattern that will find your example table names
and table names that have mixed bracket/no bracket formats:

sPatrn = "\b(?:from|join)\s" _
& "(" _
& "(?:(?:\w+|\[\w+\])?\.){0,2}" _
& "(?:\w+|\[\w+\])" _
& ")"

Note that this pattern will also find names in the form ".word.word",
which is not on your list of valid formats. To eliminate that
possibility, you need to add a negative look-ahead:

sPatrn = "\b(?:from|join)\s" _
& "(?!(?:\.\[?\w+\]?){2})" _
& "(" _
& "(?:(?:\w+|\[\w+\])?\.){0,2}" _
& "(?:\w+|\[\w+\])" _
& ")"

--
Steve

War is God's way of teaching Americans geography. -Ambrose Bierce


.



Relevant Pages

  • Re: RegEx
    ... This works for me but if there is a more compact definition, ... your current pattern will match only cases where all the table ... names are in brackets or none of them are. ... and table names that have mixed bracket/no bracket formats: ...
    (microsoft.public.scripting.vbscript)
  • Re: Is this C program doing what it is supposed to do ?
    ... Richard started by boiling it down to single letter names. ... advocating against the pattern itself, ... Even inside brackets, it becomes an eysore in some cases: ...
    (comp.lang.c)
  • Re: Error in RowFilter Like Operation
    ... characters should be escaped in brackets. ... a pattern, or at the end of a pattern, or at the beginning of a ... "ItemName LIKE '*product'" ... Wildcards are not allowed in the middle of a string. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: regexprep wildcard problem
    ... per isakson wrote: ... into 'atp', ... brackets. ... the pattern isn't anchored to only match terminal \ ...
    (comp.soft-sys.matlab)