Help with a Perl Regular Expression

E

Eric B.

Hi,

I'm hoping someone can help me come up with a regular expression that I need
to match the following.

I'm looking to match all occurances of format <word>.<word> in a string that
is not followed by the words AS. This is coming from an SQL select
statement.

Basically, I'm looking to match all the field names in an SQL select
statement that are not being aliased.

For example, in the following statement:

Select
payment_module.module_name as `alias.name`,
payment_module.module_description,
payment_module.is_enabled,
configuration.configuration_key,
configuration.configuration_value,
configuration.store_id as `alias.storeid`


I'm looking to match only:
payment_module.module_description
payment_module.is_enabled
configuration.configuration_key
configuration.configuration_value

Ideally, am looking for an expression using subexpressions that further
seperate the table name from the field name in this select statement:
ie: payment_module and module_description
payment_module and is_enabled
configuration and configuration_key
configuration and configuration_value


Any help would be greatly appreciated. So far I've managed to come up with:
/(?<!as )(?>([A-Z0-9_-]*)\.([A-Z0-9_-]*))(?![ ]+as[ ]+[A-Z0-9_\-.]+)/i

but that doesn't seem to work as it sees the expression alias.name as not
being preceeded by "as ".

Thanks!

Eric
 
J

Jim Gibson

Eric B. said:
Hi,

I'm hoping someone can help me come up with a regular expression that I need
to match the following.

I'm looking to match all occurances of format <word>.<word> in a string that
is not followed by the words AS. This is coming from an SQL select
statement.


Select
payment_module.module_name as `alias.name`,
payment_module.module_description,
payment_module.is_enabled,
configuration.configuration_key,
configuration.configuration_value,
configuration.store_id as `alias.storeid`

Any help would be greatly appreciated. So far I've managed to come up with:
/(?<!as )(?>([A-Z0-9_-]*)\.([A-Z0-9_-]*))(?![ ]+as[ ]+[A-Z0-9_\-.]+)/i

but that doesn't seem to work as it sees the expression alias.name as not
being preceeded by "as ".

Unaliased table.column names are followed directly by a comma (at least
in all of your examples), so you can use:

/([\-\w]+)\.([\-\w]+)\s*,/ig

Note the following:

1. you need the 'g' modifier to catch all occurrences on a line.
2. the \w character class is equivalent to [a-zA-Z_0-9]
3. you need to escape '-' to use it as is in a character class (2
occurrences in your reqex do not).


-----------== Posted via Newsfeed.Com - Uncensored Usenet News ==----------
http://www.newsfeed.com The #1 Newsgroup Service in the World!
-----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top