<?php
$target="This is a test | dont present me!";
$pattern="/\| (.*?)/";
$target= preg_replace($pattern, '', $target);
echo $target;
?>
I am trying to get rid of everything that is from the pipe line towards the right.. but the regular expression doest work. what am I missing?
Try the following:
You simply don’t need the parentheses, since you don’t repeat it and don’t reuse in the replacement. And the question mark is superfluous after the
*, both are quantifiers. (And @wrikken’s comment is right,*?is the lazy version of*.)