2012-11-18 48 views
2

我有一個字符串看起來像這樣一個巨大的文件:註冊Expr的格式化刪除標點符號手機號碼

ABS; Ba; Accountant/Belastingconsulent;Nederlands;2001/04/03;2001/04/03;Hollestraat 32a 9450 HAALTERT;straat xxa;9450;HALTER;+32 (53) 12.34.56;+32 (53) 12.34.56;;Beekstraat 67/1 9300 AALST;Beekstraat 67/1;9300;AALST;+32 (53) 12.34.56;+32 (53) 12.34.56;+32 (474) 12.34.56;; 
1;[email protected]; deepurllink; 

的若干領域處於不可用的格式現在:

;+32 (53) 12.34.56;+32 (53) 12.34.56;;Somestraat 67/1 9300 AALST;Somestraat 67/1;9300;AALST;+32 (53) 12.34.56;+32 (53) 12.34.56;+32 (474) 12.34.56;; 

我需要找到至少手機號碼並將其格式化爲:

;+32 (474) 12.34.56; 

;+32474123456; 

如果有人可以建議一個reg expr來查找並替換它,我將不勝感激。

+1

您使用哪種語言/工具? –

回答

2

我不想去猜測..這裏是信息,這將有助於你:

正則表達式:/;(\+[0-9]{2}) \(([0-9]{2,3})\) ([0-9]{2}).([0-9]{2}).([0-9]{2})/g

模式:;(\+[0-9]{2}) \(([0-9]{2,3})\) ([0-9]{2}).([0-9]{2}).([0-9]{2})

替換:;$1$2$3$4$5

在這裏,我們擷取5組:

group 1: (\+[0-9]{2}) 
group 2: ([0-9]{2}) 
group 3: ([0-9]{2}) 
group 4: ([0-9]{2}) 
group 5: ([0-9]{2}) 

輸入:

ABS; Ba; Accountant/Belastingconsulent;Nederlands;2001/04/03;2001/04/03;Hollestraat 32a 9450 HAALTERT;straat xxa;9450;HALTER;+32 (53) 12.34.56;+32 (53) 12.34.56;;Beekstraat 67/1 9300 AALST;Beekstraat 67/1;9300;AALST;+32 (53) 12.34.56;+32 (53) 12.34.56;+32 (474) 12.34.56;;1;[email protected]; deepurllink 

輸出:

ABS; Ba; Accountant/Belastingconsulent;Nederlands;2001/04/03;2001/04/03;Hollestraat 32a 9450 HAALTERT;straat xxa;9450;HALTER;+3253123456;+3253123456;;Beekstraat 67/1 9300 AALST;Beekstraat 67/1;9300;AALST;+3253123456;+3253123456;+32474123456;;1;[email protected]; deepurllink 
-1

對於;+32 (474) 12.34.56;成爲;+32474123456;,發現/[.() ]/g並沒有更換。

+0

如果其他文本包含'()'。在你的情況下,我也會替換掉所有的退格 –

+0

我知道,但我只是回答他的格式化數字從'; +32(474)12.34.56;'到'; +32474123456; –