[newbie] How can I catch a C comment with a regex?

B

Belbo

Hi,
I've tried to catch C comments (/* ... */) with a cycle like this:

while(($comm =~ /\/\*/) and
($comm !~ /\*\//) and
(defined($next_line=<IN_FICH>)))
{$comm=$comm.$next_line;}
print $comm

I'm sure there's an another way less stupid. But what?

Bye
 
P

Paul Lalli

Belbo said:
Hi,
I've tried to catch C comments (/* ... */) with a cycle like this:

while(($comm =~ /\/\*/) and
($comm !~ /\*\//) and
(defined($next_line=<IN_FICH>)))
{$comm=$comm.$next_line;}
print $comm

I'm sure there's an another way less stupid. But what?

I have no idea by what criteria you're defining stupidity in this case.
Regardless:

Please check the Perl FAQ *before* posting to this group:
perldoc -q comment

Paul Lalli
 
J

Jürgen Exner

Belbo said:
Hi,
I've tried to catch C comments (/* ... */) with a cycle like this:

[Attempt at parsing a programming language using REs snipped]

You don't. Programming langauges are too complex to be parsed by REs.
Just one issue (the most trivial one) that apparently you didn't think
about: What if the /* appears inside of text?
I'm sure there's an another way less stupid. But what?

Use a parser to parse a programming language.

jue
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,161
Messages
2,570,892
Members
47,427
Latest member
HildredDic

Latest Threads

Top