2012-11-12 40 views
1

的一部分,我有以下从核心银行系统正则表达式来提取字符串

This is a <test> and only <test> hope <u> understand 

从那里我想

<test><test><u> (along with <>) 

用简单的字符串,我可以做交易的格式,但它会太慢了..有什么办法来捕获使用正则表达式函数<and>之间的文本?

+0

所以你想在< and >之间的数值在数组中吗? –

+0

您的预期产出是什么? – air4x

回答

1

我能想到的是使用preg_match_all(),然后join()在一起的结果,形成了最简单的最后一个字符串:

function get_bracketed_words($str) 
{ 
    if (preg_match_all('/<[a-z]+>/', $str, $matches)) { 
     return join('', $matches[0]); 
    } 
    return ''; 
} 
0

如果你用这个,应该不会太慢(Perl代码来作为例子):

while (my $line = <FILE>) { 
    my ($request) = ($line =~ /RequestArray:(.*)/); 
    next unless $request; 
    # here, you can split $requests to sub-pieces using another regex 
    # ... 
} 
+0

对不起,我错过了你需要PHP。但它应该很容易在PHP中重写 – mvp