0

java - 如何使用java / android中的正则表达式从字符串中删除所有字母字符?

val = val.replaceAll("/A/z","");
4

3 回答 3

1

Try this:

replaceAll("[a-z]", "");

Also have a look here:

Replace all characters not in range (Java String)

于 2013-08-09T09:27:12.040 回答
1

Have a look into Unicode properites:

\p{L} any kind of letter from any language

So your regex would look like this

val = val.replaceAll("\\p{L}+","");

To remove also combined letters use a character class and add \p{M}

\p{M} a character intended to be combined with another character (e.g. accents, umlauts, enclosing boxes, etc.)

Then you end here:

val = val.replaceAll("[\\p{L}\\p{M}]+","");
于 2013-08-09T09:27:17.250 回答
1

This will remove all alphabetical characters

    String text = "gdgddfgdfh123.0114cc";
    String numOnly = text.replaceAll("\\p{Alpha}","");
于 2013-08-09T09:27:40.857 回答