【发布时间】:2017-04-20 05:26:59
【问题描述】:
我想删除 /* 和 */ 之间的字符
我尝试了正则表达式,我认为这很简单,但我对此很不满意:
示例 1:
对于这个字符串:
"/*当 (aa.kbqeben 为 null 且 (aa.KBICBN 为 null 或 aa.KBICBN='NOTPROVIDED') then '******TODO******' */else 'ok ' end nature_trans,"
我只想保留:“else 'interbancaire' end nature_trans”,
示例 2:
对于这个字符串:
"来自 prod.TbSepemi /*partition(P_TBSEPEMI_201601) */ aa,"
我只想保留:“来自 prod.TbSepemi aa”,
我试过了,但它不起作用:
$string = "/*when (aa.kbqeben is null and (aa.KBICBN is null or aa.KBICBN='NOTPROVIDED') then '******TODO******' */else 'interbancaire' end nature_trans,";
$string = preg_replace('/\/*[^\]]+\*\//', '', $string);
echo $string;
【问题讨论】:
-
*在每个实例中都需要转义,否则它将用作量词。例如\/*是零个或多个正斜杠。为什么要找非]?