我有以下来自核心银行系统的交易格式
This is a <test> and only <test> hope <u> understand
从我想要的地方
<test><test><u> (along with <>)
使用简单的子串我可以做到这一点,但它太慢了。有没有办法使用正则表达式函数来捕获< and >
之间的文本?
发布于 2012-11-12 17:34:10
我能想到的最简单的方法是使用preg_match_all()
,然后将结果join()
在一起,形成最终的字符串:
function get_bracketed_words($str)
{
if (preg_match_all('/<[a-z]+>/', $str, $matches)) {
return join('', $matches[0]);
}
return '';
}
发布于 2012-11-12 16:03:37
如果您使用它,它应该不会太慢(这里以Perl代码为例):
while (my $line = <FILE>) {
my ($request) = ($line =~ /RequestArray:(.*)/);
next unless $request;
# here, you can split $requests to sub-pieces using another regex
# ...
}
https://stackoverflow.com/questions/13340023
复制相似问题