从不包含非拉丁字符的字符串中删除所有特殊字符 [英] Remove all special characters from a string not including non-latin characters

查看:211
本文介绍了从不包含非拉丁字符的字符串中删除所有特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想删除字符串中除数字和普通az字符之外的所有特殊字符。

I want to remove all the special characters from a string except numbers and normal a-z characters.

我这样做:

text = text.replaceAll("[^a-zA-Z0-9 ]+", "");

这种方式的问题是它还会删除所有非拉丁字符,如è,é, ê,ë和其他许多人。

The problem with this way is that it will also remove all non-latin characters like è, é, ê, ë and many others.

非特殊字符(我要保留的字符)是指所有语言的所有数字和所有字母字符或至少尽可能多。

By non-special characters (the ones I want to keep) I mean all the numbers and all the alphabetical characters for all the languages or at least as many as possible.

我如何只删除特殊字符?

How do I only remove the special characters?

推荐答案

您可以尝试 \p {L} 获取所有字母, \p {N} 对于所有数字:

You can try \p{L} for all letters and \p{N} for all numbers:

text = text.replaceAll("[^\\p{L}\\p{N} ]+", "");

这篇关于从不包含非拉丁字符的字符串中删除所有特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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