Re: RegEx

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



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: 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)
  • Re: Help simplify complex regexp needing positive lookahead and reluctant quantifers
    ... eols. ... Once I changed my pattern to check for that explicitly, ... following (each group surrounded by brackets): ... Note that I've removed the initial spaces and dashes. ...
    (comp.lang.java.programmer)