You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oro-user@jakarta.apache.org by lu...@accenture.com on 2001/06/11 13:30:16 UTC
question about jakarta-oro 2.0.3
Hi,
my name is Luigi Zoso and I'm currently trying to automatically remove
comments from files containing Javascript code, by using jakarta-ORO's
"Util.substitute()" API. I built a java class by following the guidelines
of substituteExample.java.
I'm experiencing some problems when I try to delete comments of the type:
/* This is a comment */
The problem is to find the correct regular expression in order to match
these comments and replace them with a blank string in the file.
At present, I use the following expression:
(\/+[\*]+[^\*\/]+[\*]+\/)
I put the "[^\*\/]" in order to avoid removing code between two comments,
like in this example:
/*First comment*/
Function myFunction()
{alert("I don't want to delete this code");}
/*Second comment*/
This works for simple cases, such as single comments isolated from the rest
of the code, but it fails with more complex cases such as when a "/" is
present inside the comment:
/*First comment*/
Function myFunction()
{alert("I don't want to delete this code");}
/*Second comment with / inside it */
Could anyone help me with a more useful regular expression?
Thank you
Luigi Zoso
This message is for the designated recipient only and may contain
privileged or confidential information. If you have received it in error,
please notify the sender immediately and delete the original. Any other
use of the email by you is prohibited.
Re: question about jakarta-oro 2.0.3
Posted by Rex Cooper <re...@zen.co.za>.
The perl regular expression you are looking for is
s/\/\*.*\*\///
Remember that * and / are special characters and need to be escaped as \*
and \/
So, the expression above reads
s/ -- start of substitution
\/\* -- match /*
.* -- The means any non newline character (This would include the / that
you had in your second example
\*\/ -- match */
// -- replace the matched expression with nothing (in otherwords, remove
it)
That would work as long as the /* and */ are on the same line
Not sure how to do this with ORO
----- Original Message -----
From: <lu...@accenture.com>
To: <or...@jakarta.apache.org>
Sent: Monday, June 11, 2001 1:30 PM
Subject: question about jakarta-oro 2.0.3
> Hi,
> my name is Luigi Zoso and I'm currently trying to automatically remove
> comments from files containing Javascript code, by using jakarta-ORO's
> "Util.substitute()" API. I built a java class by following the guidelines
> of substituteExample.java.
> I'm experiencing some problems when I try to delete comments of the type:
> /* This is a comment */
> The problem is to find the correct regular expression in order to match
> these comments and replace them with a blank string in the file.
> At present, I use the following expression:
> (\/+[\*]+[^\*\/]+[\*]+\/)
> I put the "[^\*\/]" in order to avoid removing code between two comments,
> like in this example:
>
> /*First comment*/
> Function myFunction()
> {alert("I don't want to delete this code");}
> /*Second comment*/
>
> This works for simple cases, such as single comments isolated from the
rest
> of the code, but it fails with more complex cases such as when a "/" is
> present inside the comment:
>
> /*First comment*/
> Function myFunction()
> {alert("I don't want to delete this code");}
> /*Second comment with / inside it */
>
> Could anyone help me with a more useful regular expression?
> Thank you
> Luigi Zoso
>
>
> This message is for the designated recipient only and may contain
> privileged or confidential information. If you have received it in error,
> please notify the sender immediately and delete the original. Any other
> use of the email by you is prohibited.
>
>