我想删除任何内容:
我试过这个
string.gsub! /\W\D/, ''
Run Code Online (Sandbox Code Playgroud)
但这会消除重音.
"héllo3".gsub /\W\D/, '' #=> hllo3
Run Code Online (Sandbox Code Playgroud)
我试过了,\P{Alnum}但这删除了破折号.
我需要像......
"héllo - there - 1".gsub /regex/ #=> héllo-there-1
Run Code Online (Sandbox Code Playgroud)
这是一个Rubular:http: //rubular.com/r/RjWwdNka8S
明显的答案似乎有效.
[^-\p{Alnum}]
Run Code Online (Sandbox Code Playgroud)
指定既不是破折号也不是Alnum类成员的字符.
演示:http://rubular.com/r/pYm9hViNHz
| 归档时间: |
|
| 查看次数: |
1003 次 |
| 最近记录: |