作者cutekid (可爱小孩子)
看板RegExp
标题Re: [问题] 找出不包含特定字串的行?
时间Mon Mar 19 21:45:31 2018
Regex: \[\d+,"[^"]*(?<!US|CN)"[^\n]+\n
※ 引述《no1kk (心中在下雨)》之铭言:
: 文件内容如下
: [
: [707860,"UA","Hurzuf"],
: [519188,"RU","Novinki"],
: [1283378,"NP","Gorkhā"],
: [1270260,"IN","State of Haryāna"],
: [708546,"UA","Holubynka"],
: [1283710,"NP","Bāgmatī Zone"],
: [529334,"RU","Mar’ina Roshcha"],
: [1269750,"IN","Republic of India"],
: [1283240,"NP","Kathmandu"],
: [703363,"UA","Laspi"],
: [3632308,"VE","Merida"],
: [473537,"RU","Vinogradovo"],
: [384848,"IQ","Qarah Gawl al ‘Ulyā"],
: [569143,"RU","Cherkizovo"],
: [713514,"UA","Alupka"],
: [2878044,"DE","Lichtenrade"],
: ...
: 这是一个包含 城市id、国家、城市名称 的 json 档
: 因为我现在只想要某些特定国家的城市就好
: 要把不用的部分都删掉
: 假设我想留下的是 US & CN
: 我使用 notepad++ 的搜寻取代功能 - 规则运算式
: 搜寻:
: .+"(?<!US|CN)",.+\n
: 取代:
: 但这只会找出国家栏位是空白的行
: 如 [6255149,"","North America"],
: 无法找出国家非 US or CN 的行
: 请问我应该怎麽下条件呢?
: 感谢!!
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 111.246.56.126
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/RegExp/M.1521467133.A.01A.html
1F:推 goldie: 高手推!lookahead/lookbehind各家实作都不太一样,难以掌握 03/20 00:33
2F:推 no1kk: 感谢你,成功了!!! 03/20 11:28