|
-
Sep 29th, 2004, 10:35 PM
#1
Thread Starter
Fanatic Member
[solved] RegEx for comments
How do I catch up the C# comments?
Code:
// This is a comment
/// This is a comment
/* This
is
a
comment
*/
Code:
$comments="/(\/\/.*\n)/";
$string=preg_replace($comments,"<span style='color:#007700'>$1</span>",$string);
Didn't work. Any help is greatly appreciated. Thank you.
Last edited by brown monkey; Oct 1st, 2004 at 03:23 AM.
-
Sep 30th, 2004, 05:53 AM
#2
I would recommend you do it in two steps, once for the // and once for the /* */ comments.
Code:
cpp_comment = '|(//.*)\n|';
$string=preg_replace($cpp_comment,"<span style='color:#007700'>$1</span>\n",$string);
c_comment = '|(/\*.*\*/)|s';
$string=preg_replace($c_comment,"<span style='color:#007700'>$1</span>",$string);
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Oct 1st, 2004, 03:23 AM
#3
Thread Starter
Fanatic Member
Thank you CornedBee.
-
Oct 1st, 2004, 03:31 AM
#4
Don't forget to turn off the greediness:
PHP Code:
c_comment = '/(\\/\\*.*\\*\\/)/sU';
-
Oct 1st, 2004, 03:32 AM
#5
Thread Starter
Fanatic Member
Ok. I'll remember that. Thank you again. Thank you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|