drblhw5731
2014-12-30 06:18
浏览 34
已采纳

Golang匹配破折号(连字符)

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

图片转代码服务由CSDN问答提供 功能建议

Golang以匹配破折号(连字符)

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

此匹配-(破折号)字符

但是我想要一个不包含破折号的正则表达式。

我尝试了以下操作,但抓到了 + 字符:

 <代码> regexp.MustCompile(`[^ [0-9A-ZA-Z \  - ] \ s]的`)
regexp.MustCompile(`[^ [0-9A-ZA-Z  -] \ s]`)
   
 
 

如何匹配非字母数字和非-的字符 (破折号)?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doubei5114 2014-12-30 06:20
    已采纳

    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.

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题