删除 / 斜杠之间的单词


remove words between / Slash

我需要删除斜杠之间的单词我有这个字符串:

This a test UP/PL/EX/TU 2013
this a test 2 MG/MF/RS/TB 2007

我需要这个输出

This a test 2013
this a test 2 2007

字符串是动态的,总是变化。

可以在正则表达式时完成吗?

我相信有一个更好的表达式,但考虑到问题中的字符串,这可能已经足够好了。

$string='This a test UP/PL/EX/TU 2013';
$output=preg_replace("/'s['w'/]+'s/", " ", $string);
echo $output;
$s1 = 'This a test UP/PL/EX/TU 2013';
$s2 = ' this a test 2 MG/MF/RS/TB 2007';
$regex = '|'s*(?:[[:alnum:]]+/)+[[:alnum:]]+'s*|';
echo "$s1 => '", preg_replace($regex, ' ', $s1), "'n";
echo "$s2 => '", preg_replace($regex, ' ', $s2), "'n";

输出:

This a test UP/PL/EX/TU 2013 => 'This a test 2013
 this a test 2 MG/MF/RS/TB 2007 => ' this a test 2 2007

你可以使用这个:

$result = preg_replace('~'h*+'w*+'/(?>'w+'/?)++'h*+~', ' ', $string);