从雅虎管道中的项目中获取子字符串
以下情况:
item.
content => "This is a 48593 test"
title => "the title"
item.
content => "This is a 48593 test 3255252"
title => "the title"
item.
content => "This 35542 is a 48593 test"
title => "the title"
item.
content => "i havent exactly 5 digits 34567654"
title => "the title"
这是我在管道控制台中的当前项目,
不,我想将“内容”替换为“恰好有 5 位数字的数字的最后一个匹配项”。 想要的结果:
item.
content => "48593"
title => "the title"
item.
content => "48593"
title => "the title"
item.
content => "48593"
title => "the title"
item.
content => ""
title => "the title"
有没有办法在 pypes 2 中做到这一点?
如果有不清楚的地方请评论
following situation:
item.
content => "This is a 48593 test"
title => "the title"
item.
content => "This is a 48593 test 3255252"
title => "the title"
item.
content => "This 35542 is a 48593 test"
title => "the title"
item.
content => "i havent exactly 5 digits 34567654"
title => "the title"
this is my current item in the console of pipes
no i want to replace "content" with "the last match of a number that has exactly 5 digits.
wanted result:
item.
content => "48593"
title => "the title"
item.
content => "48593"
title => "the title"
item.
content => "48593"
title => "the title"
item.
content => ""
title => "the title"
is there a way to do this in pypes 2?
please comment if something is unclear
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
像这样使用正则表达式模块:
在 item.content 中将
(.*)
替换为X $1
在 item.content 中替换
.*\b(\d{5 })\b.*
为$1
在 item.content 中,将
X .*
替换为空(将字段留空)这是一个示例管道
一些解释
\d{5}
恰好找到五位数字X
标记正则表达式不匹配的字符串,以便在*
是一个贪心运算符。Use the regex module like this:
In item.content replace
(.*)
withX $1
In item.content replace
.*\b(\d{5})\b.*
with$1
In item.content replace
X .*
with nothing (leave field empty)Here's an example pipe
Some Explanations
\d{5}
finds exactly five digits\b
word boundaries, so that numbers with more digits are not foundX
at the beginning marks strings where the regular expression doesn't match to delete them afterwards*
is a greedy operator.抱歉,我除了 Python 之外什么都不知道
,但由于我对你的问题感兴趣,并且正则表达式在所有语言中或多或少都是相同的,所以我在 Python
结果
中提出了我的解决方案'AAA' 和 'ZZZ' 没有其他实用程序显示第 4 个结果给出“”
groups("") 中的 "" 在没有匹配项时给出默认值 ""
否则,第四个结果将为 None :
结果为
sorry , i don't know anything else than Python
but as your problem interested me and that regexes are more or less the same in all the langages, I propose my solution in Python
results
The 'AAA' and 'ZZZ' have no other utility to show that the 4th result gives ""
The "" in groups("") gives the default value "" when there is no match
Otherwise the 4th result would be None :
results in