论坛首页 Web前端技术论坛

JavaScript内核系列 第6章 正则表达式

浏览 12760 次
精华帖 (13) :: 良好帖 (0) :: 新手帖 (4) :: 隐藏帖 (0)
作者 正文
   发表时间:2010-05-06  
第七章 正则表达式:http://www.iteye.com/topic/658473
0 请登录后投票
   发表时间:2010-05-26  
var pattern = /\w{4}(\d{4})(\w{2})/;
var result = pattern.exec("yunn0871cg");
print("city code = "+result[1]+", county code = "+result[2]);
result = pattern.exec("shax0917cc");
print("city code = "+result[1]+", county code = "+result[2]);


为了匹配不同城市的简称,如上海(shangh021sh),呼和浩特(huhht0471hhht)等,应该修改为
var pattern = /[a-zA-Z]{2,8}(\d{3,4})(\w{2,5})/;
0 请登录后投票
论坛首页 Web前端技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics