in reply to replacing code with regex
Based on my first look at it I can already give these hints: (I'm still looking at it though)
(This first point follows on reasonablekeith's point:) You use \W*? to match optional whitespace, but \W represents a non-word charachter, and \s represents whitespace... also do you really want to make it non-greedy? I would suggest replacing \W*? with \s*, and also I would not give it the comment optional whitespace... (but that's just me)
What I supsect is wrong is this part of the regex: \W*?([^,]*?)\W*?,
You are making the [^,] optional and non greedy... Maybe \W*? eats all the non-comma symbols? Something like: \s*([^,]+),\s* might be better. Verifying by capturing \W*? shows that this is the problem. (as in $2 holds '")')
And, if you post a message with a regex then you might want to give both the input and the output you expect, you described it, but giving the actual string makes it easier for everyone to verify...
Update: I did some further investigating, and here is a regex that works... (or atleast as far as I can tell):
s/^ \s* my \s* \(?\s* \$page # page is the variable \s*\)? \s* = \s* \&? # function may or may not be explicitly contexted create_page # function name \s* \(\s* # Begin param ([^,]+?), # 1st param \s* ([^,]+?), # 2nd param \s* ([^,]+?), # 3th param \s* ([^,]+?) # 4th param \s*\) # End param ; /your_replace_string/x;
Also note that the /g in your regex is useless, since you have the ^... which will only match at the start of the string (unless ofcourse when you have /m too, but that's not the case in your example)
|
|---|