Hi,
I would need a simple regexp urgently for php preg_replace:
Input: Quick brown :no: fox etc Output: Quick brown !|no|! fox etc
:something: to !|something|!
Thanks
Hi,
I would need a simple regexp urgently for php preg_replace:
Input: Quick brown :no: fox etc Output: Quick brown !|no|! fox etc
:something: to !|something|!
Thanks
$output = preg_replace('/:([^ ]+):/', '!|$1|!', $input);
You might want to replace [^ ]
with a more specific set, depending on what you are expecting to be in between the :
s.
That depends on if a space is allowed between the colons. If it isn't:
$out = preg_replace('!:([^ ]+):!', '!|$1|!', $in);
is fine. You may also want to consider using a non-greedy expression instead:
$out = preg_replace('!:(.+?):!', '!|$1|!', $in);
Here is another option:
$out = preg_replace('!:([^:]+):!', '!|$1|!', $in);