【发布时间】:2017-05-30 20:59:53
【问题描述】:
我需要构建一个正则表达式,它以速率符号 @ 开头的三个取反,然后是 1 到 12 位之间不同长度的数字,并以三个 @ 符号结尾。应该选择除此之外的任何内容。
基本上我的挑战是我有一个数据框,它有一个文本语料库和一个模式@@@0-9@@@ 中的值我想删除除此模式之外的所有内容。我已经能够将正则表达式开发为[@][@][@]\d{1,12}[@][@][@],但是我想要否定这种模式,因为我想做查找和替换。例如
my name is x and i work at @@@12354@@@ and i am happy with my job. what is your company name? is it @@@42334@@@? you look happy as well!!
应该返回@@@12354@@@ @@@42334@@@,这样在各个元素之间有一个空格分隔符会很棒。有什么帮助吗?
我将在 python pandas 数据框 uisng str.replace 函数中使用这个正则表达式。
我已经尝试过regexr.com 和regex101.com 并且已经到此为止了
**编辑:**下面是数据
SNo details
1 account @@@0000082569@@@ / department stores uk & ie credit control operations
2 academic @@@0000060910@@@ , administrative, and @@@0000039198@@@ liaison coordinator
3 account executive, financial @@@0000060910@@@ , enterprise and partner group
4 2015-nasa summer internship- space power system @@@0000129849@@@ and testing
5 account technical @@@0000185187@@@ , technical presales, systems engineer
6 account @@@0000082569@@@ for car, van & 4x4 products in the east of england
7 account @@@0000082569@@@ for mikro segment and owners of the enterprises
8 account @@@0000082569@@@ - affinity digital display, mobile & publishing
9 account @@@0000082569@@@ @@@0000060905@@@ -energy and commodities @@@0000086889@@@ candidate
10 account @@@0000082569@@@ for companies department of external relevance
【问题讨论】:
-
一个更简单的正则表达式是@{3}\d+@{3}
-
您可以将
.findall与r'@{3}\d+@{3}'一起使用,然后加入找到的匹配项。 -
如果我用 [^@{3}\d+@{3}] 做否定,它不仅是对模式的否定,也是对模式之外的任何其他数字的否定
标签: python regex regex-negation