如何将 unicode 单词与 ruby​​ 1.9 匹配? [英] How to match unicode words with ruby 1.9?

查看:38
本文介绍了如何将 unicode 单词与 ruby​​ 1.9 匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ruby​​ 1.9 并试图找出我需要哪个正则表达式来实现这一点:

I'm using ruby 1.9 and trying to find out which regex I need to make this true:

Encoding.default_internal = Encoding.default_external = 'utf-8'
"föö".match(/(\w+)/u)[1] == "föö"
# => false

推荐答案

# encoding=utf-8 
p "föö".match(/\p{Word}+/)[0] == "föö"

这篇关于如何将 unicode 单词与 ruby​​ 1.9 匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆