我有一個正在使用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