的一部分,我有以下從核心銀行系統正則表達式來提取字符串
This is a <test> and only <test> hope <u> understand
從那裏我想
<test><test><u> (along with <>)
用簡單的字符串,我可以做交易的格式,但它會太慢了..有什麼辦法來捕獲使用正則表達式函數<and>
之間的文本?
的一部分,我有以下從核心銀行系統正則表達式來提取字符串
This is a <test> and only <test> hope <u> understand
從那裏我想
<test><test><u> (along with <>)
用簡單的字符串,我可以做交易的格式,但它會太慢了..有什麼辦法來捕獲使用正則表達式函數<and>
之間的文本?
我能想到的是使用preg_match_all()
,然後join()
在一起的結果,形成了最簡單的最後一個字符串:
function get_bracketed_words($str)
{
if (preg_match_all('/<[a-z]+>/', $str, $matches)) {
return join('', $matches[0]);
}
return '';
}
如果你用這個,應該不會太慢(Perl代碼來作爲例子):
while (my $line = <FILE>) {
my ($request) = ($line =~ /RequestArray:(.*)/);
next unless $request;
# here, you can split $requests to sub-pieces using another regex
# ...
}
對不起,我錯過了你需要PHP。但它應該很容易在PHP中重寫 – mvp
所以你想在< and >之間的數值在數組中嗎? –
您的預期產出是什麼? – air4x