And the output is -use strict; use warnings; my $stmt0 = "SELECT table.field0, table.field1\nFROM table0;\n"; my $stmt1 = "SELECT table.field0, table.field1\nFROM table1\nWHERE fie +ld0 = 'foo';\n"; my $nameA = $1 if $stmt0 =~ m/^FROM\s+(\S+)$/ms; my $nameB = $1 if $stmt1 =~ m/^FROM\s+(\S+)$/ms; my $name0 = do { $stmt0 =~ m/^FROM\s+(\w+)(;*?)$/ms; $1 }; my $name1 = do { $stmt1 =~ m/^FROM\s+(\w+)(;*?)$/ms; $1 }; print "table name A ='$nameA'\n"; print "table name B ='$nameB'\n"; print "table name 0 ='$name0'\n"; print "table name 1 ='$name1'\n";
Notice that in table name A, there is a ';' because of the ; character. The new regex is capable of filtering it out.table name A ='table0;' table name B ='table1' table name 0 ='table0' table name 1 ='table1'
In reply to Re: Re: Re: regular expression across lines?
by Roger
in thread regular expression across lines?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |