Re: RegEx
- From: "Steve Fulton" <cerberus40@xxxxxxxxxxx>
- Date: Fri, 10 Mar 2006 08:41:15 -0500
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
.
- Follow-Ups:
- Re: RegEx
- From: HSalim[MVP]
- Re: RegEx
- References:
- Prev by Date: Re: Replacing a line in a text file
- Next by Date: copy file generic & recursivity & concatenation
- Previous by thread: Re: RegEx
- Next by thread: Re: RegEx
- Index(es):
Relevant Pages
|