正则表达式PHP,删除2个字符之间的字符

时间:2016-12-05 18:15:13

标签: php regex

我想删除/ *和* /

之间的字符

我试过Regex,我认为这很简单,但我对此非常不满:

示例1:

这个字符串:

“/ * when(aa.kbqeben为null且(aa.KBICBN为null或aa.KBICBN ='NOTPROVIDED')然后'****** TODO ******'* / else'确定'end nature_trans,“

我只想保留:“其他'interbancaire'结束nature_trans,”

示例2:

这个字符串:

“来自prod.TbSepemi / *分区(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;

1 个答案:

答案 0 :(得分:1)

Regex101

\/\*.*\*\/

<强>描述

\/ matches the character / literally (case sensitive)
\* matches the character * literally (case sensitive)
.* matches any character (except for line terminators)
    * Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\* matches the character * literally (case sensitive)
\/ matches the character / literally (case sensitive)
Global pattern flags
    g modifier: global. All matches (don't return after first match)