0

What regular expression can I use to remove the letters  and Ä from a String?

Regards, Raj

JWL
  • 13,591
  • 7
  • 57
  • 63
user569125
  • 1,423
  • 13
  • 29
  • 40
  • copy and paste the characters from a web page into a string constant in your editor or IDE. – Michael Dillon Feb 17 '11 at 00:43
  • This is the wrong thing to do. You have asked the wrong question to get the answer you need. – tchrist Feb 17 '11 at 01:31
  • That looks very suspiciously like an encoding mismatch. The right thing to do is not to delete things like this, but to fix the encoding properly. I very strongly suggest a 100% UTF-8 workflow. – tchrist Feb 17 '11 at 01:46

2 Answers2

0

As discussed here, I'd just whitelist these characters: ^[a-zA-Z0-9äöüÄÖÜ]*$

Community
  • 1
  • 1
Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
-1

Java Regexs support unicode, you could find the unicode codes and something like this

myNewString = myString.replaceAll("\u0000", "")
dfb
  • 13,133
  • 2
  • 31
  • 52
  • **Java regexes do not ‘support Unicode’!** This is a myth. Java merely offers a few features in that direction, but far from enough to make it truly usable. Unicode support is rudimentary and incomplete in Java. It does not even meet the barebones requirements of [Level 1 support for Unicode Regular Expressions in UTS#18](http://unicode.org/reports/tr18/). Trust me, I know. – tchrist Feb 17 '11 at 01:34
  • Err... okay, I'll rephrase, you can and probably should use unicode escape sequences rather than putting the actual character in code, I've never had a problem doing this with relatively limited experience. – dfb Feb 17 '11 at 03:30