user4211028
user4211028

Reputation:

Golang to match dash(hyphen) character

Golang to match dash(hyphen) character

regexp.MustCompile(`[^[:alnum:]\s]`)

This matches -(dash) character

But I want a regex that excludes the dash character.

I tried the following but it greps the + characters:

regexp.MustCompile(`[^[0-9A-Za-z\-]\s]`)
regexp.MustCompile(`[^[0-9A-Za-z-]\s]`)

How do I match characters that are not alphanumeric and not -(dash)?

Upvotes: 0

Views: 3569

Answers (1)

Avinash Raj
Avinash Raj

Reputation: 174796

How do I match characters that are not alphanumeric ,not -(dash) and not a space?

[^A-Za-z0-9\s-]

Remove the extra character classes from your regex. The above regex would be fine.

Upvotes: 2

Related Questions