0

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);
0

2 Answers 2

8

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

$pattern = '~///<summary>\s*///.*///</summary>~s';
Sign up to request clarification or add additional context in comments.

2 Comments

Can PHP do the common Perl idom "m(patern)"?
1

It would be easier to use a preg_match_all and do

/\/\/\/.*/

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.