For this example the regex is built from this fileinsert newtab values(1) drop table newtab create table XXXX (field1 int null) insert XXXX values(1) grant select + on XXXX to sa drop table XXXX create table XXXX (field1 int null) insert XXXX values(1) grant select + on XXXX to sa drop table XXXX rollback tran create table XXXX (field1 int null) sp_help XXXX insert XXXX values(1) grant select on XXXX to sa drop table XXXX rollb +ack tran lock table cDsnJbgnd..smfJwDlwb in share mode
This is what the regex producescreate table ([a-z]|[_])+ insert \b([a-z]|[_])+\b lock table grant
Each record ($rec) is read in from a database via DBI::DBD and interrogated like this(?-xism:(?ig:(?:create table ([a-z]|[_])+|insert \b([a-z]|[_])+\b |loc +k table|grant)))
The problem is that some of the input records are multi-statement commands (i.e. they contain more than one matched pattern) and I need to be able to split the record up into it's constituent commands (where the split would be on a matched regex pattern) and process each bit seperately before printing to the csv file.# Build regex list open KEYS,"patterns" or die "Can't open the pattern file: $!"; my $exp = Regexp::Assemble ->new(flags => 'ig',chomp => 1) ->add( <KEY +S> ); close KEYS; $exp->track( 1 ); while (get the database records) { if ($exp->match($rec) ) { # populate a csv file for a spreadsheet } }
Needs to be processed ascreate table XXXX (field1 int null) insert XXXX values(1)
Can somebody explain to me how to do this assuming I have to use Regex::Assemble to do the pattern match (and the sql to extract the records cannot be changed either !) ?create table XXXX (field1 int null) insert XXXX values(1)
In reply to Splitting a string based on a regex by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |