Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   regexp format for SQL (http://www.velocityreviews.com/forums/t909390-regexp-format-for-sql.html)

ELI 01-09-2009 04:06 AM

regexp format for SQL
 
I have a simple regexp that I want to use to format a SQL statement.

#want to format the following:
select
--to_char(last_analyzed,'HH:MI:SS PM')
*
from
user_indexes ui
where
UPPER(ui.index_name) = UPPER('fact_cnpt_pat_enct_idx')
group by
some column
order by
some other column

#to be converted to the following format:

select
--to_char(last_analyzed,'HH:MI:SS PM')
*
from
user_indexes ui
where
UPPER(ui.index_name) = UPPER('fact_cnpt_pat_enct_idx')
group by
some column
order by
some other column

#basically this should take all of the NON-SQL structures (select,
from, where, group, order) and indent them.
# so far, the only thing I've managed to do is move the SQL
structures, using the following REGEXP

#this basically inserts a \t (tab) for every occurence
\(^\(select\|from\|where\|order\|group\)\)
\t\1


#QUESTION -----------------
# is there a way to say "give me everything (in a backreference) that
is NOT found within the expression" -
# basically it needs to be the opposite of it's current logic, but I'm
not sure how to do that. Suggestions?

Tad J McClellan 01-09-2009 01:46 PM

Re: regexp format for SQL
 
ELI <brian.eliason@gmail.com> wrote:

> #want to format the following:
> select
> --to_char(last_analyzed,'HH:MI:SS PM')
> *
> from
> user_indexes ui
> where
> UPPER(ui.index_name) = UPPER('fact_cnpt_pat_enct_idx')
> group by
> some column
> order by
> some other column
>
> #to be converted to the following format:
>
> select
> --to_char(last_analyzed,'HH:MI:SS PM')
> *
> from
> user_indexes ui
> where
> UPPER(ui.index_name) = UPPER('fact_cnpt_pat_enct_idx')
> group by
> some column
> order by
> some other column


> #QUESTION -----------------
> # is there a way to say "give me everything (in a backreference) that
> is NOT found within the expression" -



No.

But there is a way to say "match where the following does not match".

It is called a "negative look-ahead assertion" (perldoc perlre).


> # basically it needs to be the opposite of it's current logic, but I'm
> not sure how to do that. Suggestions?



s/^(?!(select|from|where|order|group)\b)/\t/gm;


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


All times are GMT. The time now is 02:04 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.