hi have string,
$rt="Ability: B,Session: Session #2: Tues June 14th - Fri June 24th (9-2:00PM),Time: 9:30am,karthi";
$rt="Ability: B,Session: Session #2: Tues June 14th - Fri June 24th (9-2:00PM),Time: 9:30pm,karthi";
我使用下面的正则表达式来删除最后一个逗号(,)中的文本。
$it_nme = preg_replace('/(?<=pm,)\S*/is', '', $rt);
它适用于第二个字符串(因为在逗号之前有'pm‘文本)。对于逗号前的第二个,我们有字符串'am‘。
对于两者,我如何才能编写单一的正则表达式?
发布于 2012-03-02 02:27:50
preg_replace('/(?<=[ap]m,)\S*/is', '', $rt)
发布于 2012-03-02 02:27:05
您可以像这样使用正则表达式OR
:
$it_nme = preg_replace('/(?<=(pm|am),)\S*/is', '', $rt);
https://stackoverflow.com/questions/9521779
复制相似问题