【问题标题】:Match a special utf8 character regex匹配一个特殊的 utf8 字符正则表达式
【发布时间】:2013-08-14 16:49:46
【问题描述】:

如何匹配正则表达式中的特殊符号?

– is not the same as -; – is longer and seems to have a different character code

我没想过测试特殊字符。

我需要检查的示例字符串:

Testshop – Best fan ware | Example shop

应该返回

Testshop

我使用的正则表达式:

/[^\|\-\;\–]*/

但是它没有返回正确的结果。问题是 - 字符。

【问题讨论】:

    标签: ruby regex


    【解决方案1】:

    \ 是不必要的,除了-(破折号)。

    >> 'Testshop – Best fan ware | Example shop'[/[^|\-;–]*/]
    => "Testshop "
    

    如果您只想要字母数字字符,请使用\w+也匹配_):

    >> 'Testshop – Best fan ware | Example shop'[/\w+/]
    => "Testshop"
    

    【讨论】:

      猜你喜欢
      • 2021-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-28
      • 1970-01-01
      • 2022-11-17
      相关资源
      最近更新 更多