I am trying to work with some regular expression for preg_replace that would insert the default key = "value" if it is not in the subject.
Here is what I have:
$pattern = '/\[section([^\]]+)(?!type)\]/i'; $replacement = '[section$1 type="wrapper"]';
I want this to work out:
[section title="This is the title"]
in
[section title="This is the title" type="wrapper"]
but when there is a value, I do not want it to match. This means that it is:
[section title="This is the title" type="full"]
will remain the same.
I am using a negative lookahead incorrectly. The first part will always match, and (?! Type) becomes inappropriate. I am not sure how to place it so that it works. Any ideas?
source share