抓取地址的 Regular Expression
最近有些需求要抓地址,因此寫了一個簡單的 Regular Expression
請注意! 這個 REG 因牽連中文字,所以僅適合 UTF-8 編碼
/(.{1,2}(?:市|縣).{1,9}(?:路|街|村|里|大道)[^ \n]+)/
所以在 Java 中可直接使用,在 PHP 中需要加入 u Modifier, 如下
$patten = ‘/(.{1,2}(?:市|縣).{1,9}(?:路|街|村|里|大道)[^ \n]+)/u’;
preg_match($pattern, $content);