我有一个正在使用sed的正则表达式,但现在我需要使其在PHP中也能工作。我禁止使用系统调用。将sed字符串转换为PHP
$ cat uglynumber.txt: Ticket number : 303905694, FOO:BAR:BAR: Some text Case ID:123,456,789:Foobar - Some other text 303867970;[FOOBAR] Some text goes here Case Ref: 303658850 - Some random text here - host.tld #78854w
$ cat uglynumbers.txt | sed "s/[, ]//g;s/.*\([0-9]\{9\}\).*/\1/g" 303905694 123456789 303867970 303658850
那么,如何做PHP一样吗?
我发现了一个这样的例子,但我不能注入该正则表达式。
if (preg_match("/.../", $line, $matches)) { echo "Match was found"; echo $matches[0]; }
接受那个帮助你的答案。 :) – Till 2008-10-22 01:48:23