0

How to remove all alphabetical characters from a string usign a regular expression in java/android?

val = val.replaceAll("/A/z","");
Mr.Noob
  • 985
  • 3
  • 22
  • 58
  • 4
    Spend 5 minutes reading about [character classes](http://regex.learncodethehardway.org/book/ex4.html) and you'll know. – HamZa Aug 09 '13 at 09:26

3 Answers3

1

Try this:

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

Also have a look here:

Replace all characters not in range (Java String)

Community
  • 1
  • 1
Philipp Jahoda
  • 49,738
  • 23
  • 176
  • 183
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}]+","");
stema
  • 85,585
  • 19
  • 101
  • 125
1

This will remove all alphabetical characters

    String text = "gdgddfgdfh123.0114cc";
    String numOnly = text.replaceAll("\\p{Alpha}","");
Ruchira Gayan Ranaweera
  • 33,712
  • 16
  • 72
  • 110