-3

I am writing some regex in Javascript. Now I am trying to match a (single colon) or a (space followed by a hyphen). I know if it was just a colon or a hyphen, I could do [:-]. But I'm not sure how to match either (the colon) or (space followed by hyphen).

Trying to match (a single colon) or (a space followed by a hyphen)

dmikester1
  • 1,374
  • 11
  • 55
  • 113

1 Answers1

2

Short and simple:

:    # Literal ':'
|    # or
\s-  # a whitespace followed by literal '-'.

Or, if you don't want line breaks and whatnot:

:| -
InSync
  • 4,851
  • 4
  • 8
  • 30