正则表达式,从匹配的字符串中排除“,”

时间:2020-09-09 11:35:32

标签: regex

您好! 我有这个正则表达式:

Regex

您可以看到正则表达式(?:-|role:)??\binfo-ansible[\s|,] 我试图在这种情况下将所有字符串“ info-ansible”与规则匹配:

  • 必须以“-”或“ role:”开头(例如:角色:info-ansible)
  • 它必须以空格或“,”结束

这些规则已在正则表达式中实现

在第一场比赛中,您可以看到它与info-ansible,相匹配 我不希望比赛中包含“,”。

似乎是一个非常简单的问题,但我已经花了很多时间。

链接到在线正则表达式工具的链接中包含以下文本:https://regex101.com/r/Xixz3O/3

1 个答案:

答案 0 :(得分:0)

#include <type_traits> #include <vector> template<class T> struct my_struct { my_struct() {} explicit my_struct(T) {} template <typename U = T> explicit my_struct(std::vector<U>, std::enable_if_t<!std::is_const_v<U>, int> = 0) {} }; int main() { my_struct<const int> s(1); my_struct<int> t({1, 2}); } 捕获中使用positive lookahead

因此,使用pip install setuptools==49.6.0 代替whitespace|comma

[\s|,]

Try it online!


简体(Thx @Wiktor Stribiżew);

(?=[\s,])