More information would be useful.
You haven't provided your attempts - probably they are failing because
you are using "." and expecting it to match newlines, which it doesn't
(although that can be enabled with a flag, but it's not always the
best approach).
Depending on what you're actually trying to do, you may be better off
using a proper DDL parser for this - there are certain constructs that
regex cannot match (or can only match with an overly-complex
expression) - so unless you can guarantee these wont occur (or can
remove them from the text before the regex has to deal with it) then
you might want to look into finding/creating a full parser to do this
instead.
However, here is one possible solution that will place the name in
capture group 1:
rematch( "CREATE\s+TABLE\s+(\w+)\s*\([^()]+)\s*;" , InputText )
It assumes a few things:
1) There are no nested parentheses within the create table statement.
2) That there are no comments, strings, or other non-DDL stuff that
might contain "CREATE TABLE(...)".
3) Keywords are in uppercase (append NoCase to the function name if
they might be lower- or mixed-case).
4) Table name is not quoted and only contains alphanumerics or underscores.
That is of course matching the entire statement from start to end,
which based on your comments possibly isn't required - if you *only*
need the name, you can probably just do:
rematch( "CREATE\s+TABLE\s+(\w+)" , InputText )
And not need to worry about the parentheses at all.
If you might have non-alphanumeric characters in the name (or it might
be quoted), you could consider:
rematch( "CREATE\s+TABLE\s+([^\n(]+)" , InputText )
Which will match anything that is not newline or an opening
parenthesis for the name - you'd potentially need to then trim quotes
and spaces from that.
This is all assuming you're using CF for this - for other regex
engines there are potentially better solutions (i.e. using lookbehinds
to avoid matching groups).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: http://www.houseoffusion.com/groups/regex/message.cfm/messageid:1243
Subscription: http://www.houseoffusion.com/groups/regex/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/regex/unsubscribe.cfm