regex - regularexpression for this text sql statement or a program? -


heres sql text in file.

   select substr(to_char(ctl.tody_run_dt,'yyyymmdd'),1,8) tody_yyyymmdd,                    substr(to_char(cdr.nxt_proc_dt,'yyyymmdd'),1,8) nxt_proc_yyyymmdd,                add_months(ctl.tody_run_dt - cdr.past_accru_dys,                                        - ct.nbr_cycl_for_adj) beg_proc_dt,                                            tbl_crd )                                                                , prv.calendar_run_dt =                                                            ( select max(calendar_run_dt)                                                     run_tbl1 prv2                                                      

from wish extract tables, seems pretty complicated done through regexp? there way? or should write program? cant come algorithm.

you might able linear search this. relaxed example
, targets from keyword, excludes other keywords.

the table data captured in group 1. has split appart upon each
match through find loop.

 #  from\s+((?!(?:select|from|where|and)\b)\w+(?:[,\s]+(?!(?:select|from|where|and)\b)\w+)*)     \s+   (                # (1 start), contains table info       (?!              # exclude keywords            (?:                 select              |               |               |  ,             )            \b        )       \w+        (?:            [,\s]+                      (?!              # exclude keywords                 (?:                      select                    |                    |                    |  ,                  )                 \b             )            \w+        )*  )                # (1 end) 

perl test case

$/ = undef;  $str = <data>;  while ( $str =~ /from\s+((?!(?:select|from|where|and)\b)\w+(?:[,\s]+(?!(?:select|from|where|and)\b)\w+)*)/g ) {      print "\n'$1'"; }  __data__    select substr(to_char(ctl.tody_run_dt,'yyyymmdd'),1,8) tody_yyyymmdd,         substr(to_char(cdr.nxt_proc_dt,'yyyymmdd'),1,8) nxt_proc_yyyymmdd,         add_months(ctl.tody_run_dt - cdr.past_accru_dys,               - ct.nbr_cycl_for_adj) beg_proc_dt,        (ctl.tody_run_dt + cdr.futr_accru_dys) end_proc_dt,      ctl.tody_end_proc_dt,    ctl.prv_end_proc_dt,    cdr.fst_proc_dy,    cdr.lst_proc_dy,    cdr.accru_nbr_of_dys,    cdr.dy_of_wk,         run_tbl1 cdr, runtbl        run_tbl1 prv,        run_tbl_cntl ctl,        tbl_crd ct        cdr.calendar_run_dt = ctl.tody_run_dt       , ct.nbr_cycl_for_adj =       ( select max(nbr_cycl_for_adj)         tbl_crd )       , prv.calendar_run_dt =        ( select max(calendar_run_dt)       run_tbl1 prv2       prv2.calendar_run_dt < ctl.tody_run_dt        , prv2.accru_nbr_of_dys = 1 )        , rownum = 1 

output >>

'run_tbl1 cdr, runtbl        run_tbl1 prv,        run_tbl_cntl ctl,        tbl_crd ct' 'tbl_crd' 'run_tbl1 prv2' 

Comments

Popular posts from this blog

php - Magento - Deleted Base url key -

javascript - Tooltipster plugin not firing jquery function when button or any click even occur -

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -