user30771
user30771

Reputation: 109

What does " :\- " match?

I have the following regex:

[\s:\-]

How do I match the :\-?

Upvotes: 2

Views: 105

Answers (2)

LaintalAy
LaintalAy

Reputation: 1192

Your character class has just three components: a space type character (\s), a colon (:) or a minus (-). That way you will only match one appearance of one of those three options.

What you are looking for is a regex like /\s:\-/ without the brackets ([]).

Upvotes: 5

toolic
toolic

Reputation: 62037

YAPE::Regex::Explain

The regular expression:

(?-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
----------------------------------------------------------------------

Upvotes: 5

Related Questions