我看到了一些深入的文章,所以不确定要从正则表达式语句中删除什么。
我基本上有这个
foo:bar all the way to anotherfoo:bar;seg98y34g.?sdebvw h segvu(任何东西都可以)
我需要一个PHP正则表达式来删除冒号后面的 EVERYTHING。 第一部分可以是任意长度(但它从不包含冒号)。 因此,在上述两种情况下,我将以如下内容结束:
foo和anotherfoo
执行类似于以下可怕伪代码的操作之后
$string = 'foo:bar';
$newstring = regex_to_remove_everything_after_":"($string);
编辑
发布后,使用explode()
是否足够可靠? 像这样:
$pieces = explode(':', 'foo:bar')
$newstring = $pieces[0];