regex - Is it possible to replace a word (before or after) a phrase based on condition using regular expression in php?
Engineering School, Medical school, The School of Science, High School of science
[X] school, [X] school, The School of [X], High School of [X]
Rule: any words before the phrase
school of or (case insensitive) or School (case insensitive) needs to be replaced by
[X]. But both rule should not execute at the same time.
$inputext = "Engineering School, Medical school, The School of Science"; $rule ="/\w+(?= school)/i"; $replacetext = "[X]"; $outputext = preg_replace($rule, $replacetext, $inputext); echo($outputext);
To make it clear - the rule should be triggered based on occurrence of 'School of' and 'School' (both case insensitive). - When 'School of' is present then the rule on 'School' should not be triggered
Thanks for any suggestions.