Perl什么“:\ - ”匹配?

时间:2016-05-04 14:56:01

标签: perl

我有以下正则表达式:

[\s:\-]

我无法匹配“:\ - ”,已在互联网上进行搜索并尝试了severel组合......

2 个答案:

答案 0 :(得分:4)

YAPE::Regex::Explain

正则表达式:

(?-imsx:[\s:\-])

matches as follows:

NODE                     EXPLANATION
----------------------------------------------------------------------
(?-imsx:                 group, but do not capture (case-sensitive)
                         (with ^ and $ matching normally) (with . not
                         matching \n) (matching whitespace and #
                         normally):
----------------------------------------------------------------------
  [\s:\-]                  any character of: whitespace (\n, \r, \t,
                           \f, and " "), ':', '\-'
----------------------------------------------------------------------
)                        end of grouping
----------------------------------------------------------------------

答案 1 :(得分:4)

您的角色类只有三个组件:空格类型字符(\s),冒号(:)或减号(-)。这样,您只能匹配这三个选项之一的一个外观。

您正在寻找的是/\s:\-/这样的正则表达式,不带括号([])。