【发布时间】:2016-01-08 16:11:55
【问题描述】:
给定以下字符串
span.a.b this.is.really.confusing
我需要返回匹配的 a 和 b。我已经能够接近以下正则表达式:
(?<=\.)[\w]+
但它也匹配 is、really 和 confusing。当我包含负前瞻时,我会更接近,但我仍然不在那里。
(?<=\.)[\w]+(?=\s) # matches b, confusing
如何匹配点后的单词直到出现空格?
【问题讨论】:
-
我目前正在使用 Elixir 来编写这个正则表达式。 elixir-lang.org/docs/master/elixir/Regex.html
-
根据该链接,Elixir 中的正则表达式基于 Perl;并且根据 RegexBuddy 的说法,Perl 不支持后视中的重复。所以我会先尝试截断字符串,然后使用正则表达式。
-
感谢您的快速回复。目前我正在使用
String.split\2函数来临时解决这个问题 -
words after a dot until a whitespace occurs应该只匹配b和confusing。您能否说明您的情况,为什么它应该匹配a而不是confusing?
标签: regex