Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: matching comments

by Eugene (Scribe)
on Apr 28, 2000 at 21:49 UTC ( [id://9610]=note: print w/replies, xml ) Need Help??


in reply to matching comments

Here is another issue, merlyn's program does not catch the escaped comment. Like <CODE>Some text /*comment \*/ more comment*/<CODE>.

In fact it completely weeds the escape character out.

Any ways around it?

Replies are listed 'Best First'.
RE: Re: matching comments
by perlmonkey (Hermit) on Apr 28, 2000 at 22:52 UTC
    Quite true. Look at perlre for the comments on the "?<!" operator (zero-width negative lookbehind assertion operator).

    This will fix merlyn's code (where $file is the text you are parsing):
    my $file = shift; my $inside = 0; my $oldpos = 0; while ($file =~ /(?<!\\)(\Q$start\E|\Q$end\E)/g) { if ($1 eq $start) { if (++$inside == 1) { $oldpos = pos($file) - length($start); } } else { if (--$inside == 0) { print substr($file, $oldpos, pos($file)-$oldpos); } } }
    the (?<!\\)\Q$start\E will match what is in $start but not preceeded by a '\' character.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://9610]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-03-28 09:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found