raflach has asked for the wisdom of the Perl Monks concerning the following question:
Ok, I have a text file with the following in it:
\t\tmy($page)=&create_page(isitvalid("templatefile.html"),\%replace,\% +lists,@unhide);
NOTE: the \t's represent actual tabs in the file
I also have a script with the following regex
s/^\W* # we may have some white space at start of line my\W*? # all variable will use my \(? # variable may or may not be list \W*? # some people space out the parens and some don't \$page # assuming for now that page is always the variable \W*? # more possible space around parenthesis \)? # variable may or may not be a list \W*? # whitespce is optional = # we have to assign the variable \W*? # more optional whitespace \&? # function may or may not be explicitly contexted create_page\W*? # the name of the funciton followed by optional +space \( # parenthesis begins the parameterlist \W*? # we might have whitespace before first parameter ([^,]*?) # BROKEN: this should collect everything up to the +next comma in variable number 1 \W*? # this shouldn't be necessary since whitespace should h +ave been slurped on previous line but this shouldn't hurt either , # Got to have the separator \W*? # more optional whitespace ([^,]*?) # NOT BROKEN: this grabs everything up to the secon +d comma (of course we don't have parens and dblquotes in second param \W*? # this shouldn't be necessary since whitespace should h +ave been slurped on previous line , # Got to have the separator \W*? # more optional whitespace ([^,]*?) # NOT BROKEN: third one gets gotten fine as well \W*? # again the unnecessary whitespace collector , # Again the seperator \W*? # Again the optional whitespace ([^)]*?) # NOT BROKEN: heres our final collection point \W*? # Again with the unnecessary whitespace \) # our parameter list has come to a close \W*? # whitespace might seperate from closing punctionation thou +gh it seems unlikely ; # closing punctuation ends the statement the replace doesn't m +atter for the question /my \$renderer = new HRsmart::Lightning::Render ( template => $1 +,\n\t\tloops => $3,\n\t\treplace => $2,\n\t\tfinals => $4 );\n\$rende +rer->customize_header\( \$company_id \);\nmy \$page = \$renderer->ren +der;\n\$page =~ s\/~%.{0,20}%~\/\/g;\n/gx;
As you can see I'm trying to replace the old functional way of doing things with a new semi-oo way.
The problem is, instead of getting 'isitvalid("templatefile.html")' for $1 which is what I was expecting, it is cutting off before the second double quote, so I get 'isitvalid("templatefile.html'
Anyone can point me in the right direction?
BTW there's no chance of spaces between the doublequotes, so that's not an issue.
UPDATED: Under-commented code replaced with Over-commented code
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: replacing code with regex
by reasonablekeith (Deacon) on May 11, 2005 at 16:08 UTC | |
by raflach (Pilgrim) on May 11, 2005 at 17:38 UTC | |
by reasonablekeith (Deacon) on May 11, 2005 at 18:34 UTC | |
Re: replacing code with regex
by Joost (Canon) on May 11, 2005 at 16:09 UTC | |
Re: replacing code with regex
by Animator (Hermit) on May 11, 2005 at 18:43 UTC |