Using YAPE::Regex::Explain, this is how the first regex is being
interpreted:
The regular expression:
(?-imsx:s/^\s*function\s+(?:\w+\(\)\s*)?\s*\{\s*\n//gi)
matches as follows:
NODE EXPLANATION
----------------------------------------------------------------------
(?-imsx: group, but do not capture (case-sensitive)
(with ^ and $ matching normally) (with . not
matching \n) (matching whitespace and #
normally):
----------------------------------------------------------------------
s/ 's/'
----------------------------------------------------------------------
^ the beginning of the string
----------------------------------------------------------------------
\s* whitespace (\n, \r, \t, \f, and " ") (0 or
more times (matching the most amount
possible))
----------------------------------------------------------------------
function 'function'
----------------------------------------------------------------------
\s+ whitespace (\n, \r, \t, \f, and " ") (1 or
more times (matching the most amount
possible))
----------------------------------------------------------------------
(?: group, but do not capture (optional
(matching the most amount possible)):
----------------------------------------------------------------------
\w+ word characters (a-z, A-Z, 0-9, _) (1 or
more times (matching the most amount
possible))
----------------------------------------------------------------------
\( '('
----------------------------------------------------------------------
\) ')'
----------------------------------------------------------------------
\s* whitespace (\n, \r, \t, \f, and " ") (0
or more times (matching the most amount
possible))
----------------------------------------------------------------------
)? end of grouping
----------------------------------------------------------------------
\s* whitespace (\n, \r, \t, \f, and " ") (0 or
more times (matching the most amount
possible))
----------------------------------------------------------------------
\{ '{'
----------------------------------------------------------------------
\s* whitespace (\n, \r, \t, \f, and " ") (0 or
more times (matching the most amount
possible))
----------------------------------------------------------------------
\n '\n' (newline)
----------------------------------------------------------------------
//gi '//gi'
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
One thing I'm noticing is that this should only match if you don't pass
anything to the function. I've gotta run, but maybe this is a place to
start.
-----Original Message-----
From: Kevin Old [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 23, 2006 11:35 AM
To: Timothy Johnson
Cc: Perl Beginners
Subject: Re: Javascript Regex to Perl Regex
Here's what I have.
<snip>
# Clean js
$js =~ s/^\s*function\s+(?:\w+\(\)\s*)?\s*\{\s*\n//gi;
$js =~ s/\s*}\s*$//gi;
<snip>
If you cut and past the HTML and run it in a browser it will turn code
like this:
function wR(_1,_2,_3,_4){
var _5=document.getElementById("w"+_1);
var _4=_4||window.event;
sbHandler.prediction=_3;
RatingManager.handleMouseover(_4,_5);
}
<snip>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>