PHP的Preg匹配和过滤结果

时间:2016-05-17 10:38:32

标签: php preg-replace preg-match

我的行中有这样的东西

[0] -> * Row: {{t|fa|kuinka}}, {{t+|ti|miten}}, {{t|fi|millä tavalla|sc=Hani}}, {{t+|fi|millä tavalla|sc=Hani|sc=Td}}

我怎样才能得到这样的?

[0] ->  fa|kuinka; ti|miten; fi|millä tavalla; fi|millä tavalla

1 个答案:

答案 0 :(得分:0)

You'll need a preg_match_all call with a pattern like this:

{{[t+]{1,2}\|([^}\|]*)\|([^}\|]*)[\|]?([^}\|]+)[\|]?([^}\|]+)}}

Then you can obtain te single pieces from the resulting array, see the docs: http://php.net/manual/en/function.preg-match-all.php