2012-11-18 50 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; –