tags:

views:

96

answers:

2

Hi,

I am trying to get commented strings in my code using regular expression in php.

Let's say I have following string.

$string = "
   ///<summary>
   ///test
   ///</summary>
";

I use preg_match_all for regular expression function.

when I put $string to preg_match_all, it displays

Warning: preg_match() [function.preg-match]: Unknown modifier 'string' in /home/document/public_html/test.php on line 10

I guess it is because I have modifiers(/) in $string.

How do I get around this?

Actual Code

$string = "
///<summary
///aaa
///</summary>
";

$pattern = "/\/\/\/<summary>\/\/\/.*\/\/\/</summary";

preg_match($pattern,$a,$match);
+8  A: 

You don’t have to use / as delimiters. So try this:

$pattern = '~///<summary>\s*///.*///</summary>~s';
Gumbo
Can PHP do the common Perl idom "`m(patern)`"?
Brad Gilbert
@Brad Gilbert: See http://docs.php.net/manual/en/reference.pcre.pattern.modifiers.php
Gumbo
+1  A: 

It would be easier to use a preg_match_all and do

/\/\/\/.*/

instead. That would match all lines that have /// at the beginning

Weegee
Or even easier: |///.*|
Michael Myers