Help with a Perl Regular Expression

Discussion in 'Perl' started by Eric B., Dec 17, 2004.

  1. Eric B.

    Eric B. Guest

    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
    Eric B., Dec 17, 2004
    #1
    1. Advertising

  2. Eric B.

    Jim Gibson Guest

    In article <>, Eric B.
    <> wrote:

    > 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 =-----
    Jim Gibson, Dec 17, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VSK
    Replies:
    2
    Views:
    2,261
  2. =?iso-8859-1?B?bW9vcJk=?=

    Matching abitrary expression in a regular expression

    =?iso-8859-1?B?bW9vcJk=?=, Dec 1, 2005, in forum: Java
    Replies:
    8
    Views:
    823
    Alan Moore
    Dec 2, 2005
  3. pekka niiranen
    Replies:
    5
    Views:
    499
    Paul McGuire
    Oct 20, 2004
  4. perl regular expression help

    , Aug 7, 2006, in forum: Perl Misc
    Replies:
    2
    Views:
    131
  5. Replies:
    10
    Views:
    137
    Tad McClellan
    Nov 12, 2007
Loading...

Share This Page