码迷,mamicode.com
首页 > 其他好文 > 详细

正则表达式匹配

时间:2015-06-23 15:19:34      阅读:265      评论:0      收藏:0      [点我收藏+]

标签:

由于工作需要,学习了正则表达式匹配。从MongoDB导出的数据文本大致是这样的:

{
"_id" : ObjectId("55370b4112db760740809f79"),
"CartKey" : {
"CustomerId" : NumberLong(471)
},
"LastUpdate" : ISODate("2015-06-04T08:21:24.307Z"),
"Baskets" : [{
"Items" : [{
"SKU" : "5170",
"CategoryName" : "Cables & Adapters "
}],
"CountryCode" : 32
}]
}

{
"_id" : ObjectId("55769cc512db760da847d639"),
"CartKey" : {
"CustomerId" : NumberLong(1002)
},
"LastUpdate" : ISODate("2015-06-01T00:00:00Z"),
"Baskets" : [{
"Items" : [{
"SKU" : "2716",
"CategoryName" : "iPhone iPad iPod"
}],
"CountryCode" : 46
}]
}

{
"_id" : ObjectId("54b5e9d412db761c388d6c48"),
"CartKey" : {
"CustomerId" : NumberLong(4398734)
},
"LastUpdate" : ISODate("2015-06-05T03:49:11.131Z"),
"Baskets" : [{
"Items" : [{
"SKU" : "33883",
"CategoryName" : "Plugs & Sockets"
}, {
"SKU" : "126095",
"CategoryName" : "Household Thermometers"
}],
"CountryCode" : 46
}]
}

目标是将"CustomerId" : NumberLong(4398734)转化为"CustomerId" : 4398734   ,"LastUpdate" : ISODate("2015-06-05T03:49:11.131Z")转换为"LastUpdate" : "2015-06-05T03:49:11.131Z",

 

我使用的是NotePad++编辑器的正则替换。

 

查找目标的正则表达式是:"CustomerId" : NumberLong\((.*)\)

替换为:"CustomerId" : \1     

 

日期是:"LastUpdate" : ISODate\((.*)\)

替换为"LastUpdate" : \1

 

为什么是\1了?是因为我们都知道使用()是因为group的原因。

技术分享

系列文章:

http://zhoufoxcn.blog.51cto.com/792419/281956/

http://www.crifan.com/files/doc/docbook/rec_soft_npp/release/htmls/npp_func_regex_replace.html

 

正则表达式匹配

标签:

原文地址:http://www.cnblogs.com/cxzdy/p/4595457.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!