A nit, though. I don't know diddly 'bout JavaScript, but are backslashed backslashes allowed in strings? If so, this grammar doesn't allow for this.
Sure it does, try the perl 5 version that I have at the end:
sub quoted_string
{
my $type = quotemeta shift;
return qr/
$type
(?:
[^$type]+
|
(?<= \\ ) $type
)*
$type
/x;
}
my $data = qq(This "is a quoted string" and so is "this" and
this one "has \\\\ \\" backslashes" and other unrelated stuff);
my @matches = $data =~ / ((??{ quoted_string( qq(") ) })) /xg;
print join("\n\n",@matches);
Also, here are a few Javascript code snippets for those unfamiliar with Javascript:
<script>
function Some_Function (arg1, arg2) { }
do { } while (1)
for (i=0; i < 10; i++) { }
while (1) { }
</script>
Its pretty much just like C, for those who are familiar with that (except Javascript variables don't have types).
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|