1

I want to replace all non-alphanumeric characters, but keep Æ, Ø, Å, æ, ø, å.
Current code:

  replaceAll("\\P{Alnum}", "_")
mazaneicha
  • 8,794
  • 4
  • 33
  • 52
André Mathisen
  • 904
  • 2
  • 7
  • 15
  • 1
    possible duplicate of [Regular expression to match non-english characters?](http://stackoverflow.com/questions/150033/regular-expression-to-match-non-english-characters) – MaxZoom Mar 22 '15 at 21:05

3 Answers3

3

Use explicit white list instead:

replaceAll("[^a-zA-Z0-9ÆØÅæøå]","_")

Look at the similar question

Community
  • 1
  • 1
Nikita Astrakhantsev
  • 4,701
  • 1
  • 15
  • 26
  • Dosen't work. This one just replace all alphanumeric characters (and Æ,Ø,Å,æ,ø,å) single character to "_". I want to replace all non-alphanumeric characters except Æ,Ø,Å,æ,ø,å. You did opposite. – André Mathisen Mar 22 '15 at 21:29
0

Does below work for ya?

 replaceAll("[^A-Za-z0-9ÆØÅæøå]", "_")
MaxZoom
  • 7,619
  • 5
  • 28
  • 44
0

try this one :

replaceAll("^[a-zA-ZÆØÅæøå]*$", "_");
void
  • 7,760
  • 3
  • 25
  • 43