Reputation: 109
I have the following regex:
[\s:\-]
How do I match the :\-
?
Upvotes: 2
Views: 105
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
Reputation: 62037
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