-1

Currently i am using the following code to modify content between {| and |} using a custom function parse_table

$output = preg_replace_callback("({\|(.*?)\|})is", function($m) {return parse_table($m[1]);}, $input);

Now i want to modify it such that the pattern can exclude a certain substring, such as abcde. What could be done to achieve this?

Thank you very much.

aye
  • 301
  • 2
  • 16

1 Answers1

0

You can put it in your regex:

"({\|(?!abcde)(.*?)\|})is"

However, this would get very difficult to read, very fast. Instead, use the callback:

function($m) {
    if( $m[1] == "abcde") return $m[0];
    return parse_table($m[1]);
}
Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
  • 1
    I'm very week at regular expression. Your option to use it inside the callback is brilliant. Only one thing is you should change the conditional part to `if (strpos($m[1], 'abcde') !== false) . Thank you very much. – aye Feb 14 '14 at 14:13