Groovy Regex 用于匹配单词(即使带有重音字母)
我正在尝试对任何文本中的单词进行标记,例如:
Ça me plaît.
应标记为“ça,me,plaît”。 为此,我想清除字符串中的所有特殊字符,然后将其拆分为空格。通过这段代码:
text = text.toLowerCase().replaceAll(/^\w/, ' ')
def tokens = text.split(" ")
我得到了
a me pla t
Which 远没有用处。 我在这里需要什么正则表达式?
谢谢! 穆隆
I'm trying to tokenize words from any text, e.g.:
Ça me plaît.
Should be tokenized as "ça,me,plaît".
To do this, I want to clear the string from all special characters, and then split it on a whitespace. With this code:
text = text.toLowerCase().replaceAll(/^\w/, ' ')
def tokens = text.split(" ")
I get
a me pla t
Which is far from being useful.
What regex do I need here?
Thanks!
Mulone
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 \S(大写 S)代替 \w。 \S 匹配所有非白色字符,而 \s(非大写)匹配所有白色字符。
因此,你将拥有
You could use \S (capital S) instead of \w. \S matches all non-white characters, while \s (non-capital) matches all white characters.
Hence, you'll have
这似乎对我有用(至少对于这种情况):
This seems to work for me (at least for this situation):