Ask a Question related to PERL Miscellaneous, Design and Development.
-
Tman #1
I know I can do this with a regex, but...
Need to strip comments from VBScript code.
Tried to use a state machine to tell if I was in quotes, but got very
confused. I know I can use a regex, although I may have to call it
repeatedly to eat quoted strings. Anyone have ideas?
I need to whack everything after the first comment character...
this is not a comment
'this line is fully commented
the comment 'in this line starts after ' the word comment
there "is no 'comment" in this line
but in "this 'line" there 'is a "comment" before the word "is"
'this line is "fully" commented
ad infinitum...
Tman Guest
-
Regex help
I'd like to replace any html tags containing "< >" with a space. For example, <TR VALIGN=TOP>, I'd like to replace that with a space. Is there a... -
REGEX help pls
in the regex buddy they are explaining: "Be careful when using the negated shorthands inside square brackets. is not the same as . The latter... -
Regex..
Could some good samaritan help me out with this pls... I am trying to find a regular expression for the below string.. ExchangeName =... -
Need help with regex
> I have a directory of files that I want to move to another directory. -
IP regex?
Gareth Glaccum wrote: How about using m/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/ and testing $1 - $4 for compliance? Much cleaner. -- Cheers, -
Anno Siegel #2
Re: I know I can do this with a regex, but...
Tman <nerdy1@snet.net> wrote in comp.lang.perl.misc:
Take a look at Regex::Common. It has elaborate regexes that deal> Need to strip comments from VBScript code.
>
> Tried to use a state machine to tell if I was in quotes, but got very
> confused. I know I can use a regex, although I may have to call it
> repeatedly to eat quoted strings. Anyone have ideas?
>
> I need to whack everything after the first comment character...
>
> this is not a comment
> 'this line is fully commented
> the comment 'in this line starts after ' the word comment
> there "is no 'comment" in this line
> but in "this 'line" there 'is a "comment" before the word "is"
> 'this line is "fully" commented
with comments.
Anno
Anno Siegel Guest
-
Abigail #3
Re: I know I can do this with a regex, but...
Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMMDCLXX
September MCMXCIII in <URL:news:bkbrds$o08$1@mamenchi.zrz.TU-Berlin.DE>:
^^ Tman <nerdy1@snet.net> wrote in comp.lang.perl.misc:
^^ > Need to strip comments from VBScript code.
^^ >
^^ > Tried to use a state machine to tell if I was in quotes, but got very
^^ > confused. I know I can use a regex, although I may have to call it
^^ > repeatedly to eat quoted strings. Anyone have ideas?
^^ >
^^ > I need to whack everything after the first comment character...
^^ >
^^ > this is not a comment
^^ > 'this line is fully commented
^^ > the comment 'in this line starts after ' the word comment
^^ > there "is no 'comment" in this line
^^ > but in "this 'line" there 'is a "comment" before the word "is"
^^ > 'this line is "fully" commented
^^
^^ Take a look at Regex::Common. It has elaborate regexes that deal
^^ with comments.
But Regexp::Common will only give you patterns for comments - it
doesn't include language parsers. All the patterns of Regexp::Common
are context free - but for most languages the pattern for comments
isn't context free (for instance, they can be included in literals).
Having said that, if the only concern is double quoted strings,
something like this might work (untested):
use Regexp::Common;
s [($RE{delimited}{-delim => '"'})|'.*\n]
[$1 || ""]eg;
Abigail
--
perl -weprint\<\<EOT\; -eJust -eanother -ePerl -eHacker -eEOT
Abigail Guest
-
Philip Lees #4
Re: I know I can do this with a regex, but...
On Thu, 18 Sep 2003 02:06:53 GMT, "Tman" <nerdy1@snet.net> wrote:
The Perl FAQ gives a regex for doing this kind of splitting. However,>Need to strip comments from VBScript code.
>
>Tried to use a state machine to tell if I was in quotes, but got very
>confused. I know I can use a regex, although I may have to call it
>repeatedly to eat quoted strings. Anyone have ideas?
>
>I need to whack everything after the first comment character...
as you're only concerned about breaking into two pieces, it might be
easier to do it this way (if you don't care about efficiency).
while (<DATA>){
chomp;
my $line = "";
foreach( split // ){
unless ( /"/ ... /"/ ){ last if /'/ }
$line .= $_
}
print "$line\n" if $line;
}
__DATA__
this is not a comment
'this line is fully commented
the comment 'in this line starts after ' the word comment
there "is no 'comment" in this line
but in "this 'line" there 'is a "comment" before the word "is"
'this line is "fully" commented
Phil
--
Ignore coming events if you wish to send me e-mail
Philip Lees Guest



Reply With Quote

