【发布时间】:2016-07-26 23:27:26
【问题描述】:
我正在尝试使用正则表达式匹配以下字符串中两次出现下划线后的所有内容:ABCD__A123。我想要的输出是A123。
我目前有/__(.+)/,它会产生一个包含双下划线的输出。我在 SO 和 Google 上搜索了所有答案,但没有运气!
【问题讨论】:
-
哦,您还没有搜索过积极的后视,是吗?但是什么是正则表达式风格(编程语言/工具)?你真的需要回顾一下吗?您可以使用您的模式获取捕获的值。
-
我猜是 DataWeave。那么请阅读:The
matchoperator returns an array of matches that contains the entire matching expression, followed by all of the capture groups that match the provided regular expression. In this case($ match /([A-Z]{2,4})\d*/)[1]will return the code which will be in the first and only capture group for those identifiers it matches.。因此,您的正则表达式可以根据需要工作,您只需要访问[1]值。 -
@WiktorStribiżew 是的 DataWeave,感谢您的回复。
-
我明白了,但接受的答案以及您没有提供正则表达式风格的事实使您的问题重复。
标签: regex