Hello,
Can any body tell me i need to skip the whole text which is commented (whether multiline or single line) and match the next text with simple regexs.
e.g
/*
This is sample text_1 in multi line comments
This is sample text_2 in multi line comments
*/
Text after comments
Now i only want to match string "Text after comments" and regex whould skip whole commented text and only give me output as "Text after comments"
Regards
Muhammad Usman Khalil
Edit/Delete Message
Need to skip multiline charachters and single line character
Moderator: General Moderators
-
glitteringsound
- Forum Newbie
- Posts: 1
- Joined: Sun Jan 24, 2010 5:12 am
Re: Need to skip multiline charachters and single line character
Code: Select all
function RemoveComments( $s )
{
return preg_replace('#/\*.*?\*/#s','',$s);
}- \* instead of * because * is a special regexp char
- .*? means lazy instead of greedy (otherwise it would cut everything between the first and last comment, if multiple)
- the 's' modifier to ignore linebreaks