使用正则表达式将列表项拆分为两个项目
所以我输入了一个包含如下元素的列表:
“2008年建筑重建重铺和施工日历年” 街道和街道的修复道路”
,我正在迭代列表。对于每次迭代,首先我想验证模式 INTspacespacefor 是否在字符串中,我知道我可以这样做:
re.search('\\d+\s\sfor',string)
一旦我确认了其中一个元素的匹配,我想将此元素拆分为 INT 和“for”之间的两个元素,有没有一种简单的方法可以做到这一点
?
[item1,item2,...item10,"calendar year 2008","for construction reconstruction resurfacing & repair of streets & roads",item11,item12...]
So I have input of a list with elements like this:
"calendar year 2008 for construction reconstruction resurfacing &
repair of streets & roads"
and I'm iterating through the list. For each iteration, first I want to verify that the pattern INTspacespacefor is in the string, which I know I can do with:
re.search('\\d+\s\sfor',string)
Once I've confirmed a match on one of the elements, I want to split this element into two elements in place between the INT and the "for". Is there an easy way to do this?
So a sample output for this would be:
[item1,item2,...item10,"calendar year 2008","for construction reconstruction resurfacing & repair of streets & roads",item11,item12...]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用后视和前视
You can use look behind and look ahead