嗨有字符串,
$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'。
如何编写单个正则表达式?
答案 0 :(得分:2)
preg_replace('/(?<=[ap]m,)\S*/is', '', $rt)
答案 1 :(得分:0)
您可以像这样使用正则表达式OR
:
$it_nme = preg_replace('/(?<=(pm|am),)\S*/is', '', $rt);