Original question
I seem to have trouble seeing the obvious. I'm trying to use POSIX character classes in JavaScript. They are supported in JavaScript, aren't they?
If I type this in a console, I get the following result.
var s = "test string-banane. Aber bitte mit Sahne! 12 Stück, um genau zu sein. 12 Stück Sahne.";
console.log( s.replace(/[:alnum:]/g, "_") );
"test stri_g-b____e. Aber bitte _it S_h_e! 12 Stück, __ ge___ z_ sei_. 12 Stück S_h_e."
It reads the square brackets too literally!
Compare this to the following variation, which is rather what I'm trying to achieve (except, that method fails to cover German umlauts and stuff):
console.log( s.replace(/[0-9a-zA-Z]/g, "_") );
"____ ______-______. ____ _____ ___ _____! __ __ü__, __ _____ __ ____. __ __ü__ _____."
Using double brackets [[:alnum:]] doesn't seem to help either. That doesn't replace anything at all!
I'd appreciate it if you could help me – or point me to a solved duplicate thread. (I did use the search, though …)
Edit
Using this online tool to find the required Unicode ranges, I managed to figure out what I need. This covers German umlauts, French accents and probably more … I hope this will suffice.
var s = "test string-banane. Aber bitte mit Sahne! 12 Stück, um genau zu sein. 12 Stück ~Sahne. Voilá, alors dans l'ecole. Avec Louis de Funès. Hoëcker, Sie sind raus! Ceçille.";
s.replace( /[0-9a-zA-Z\u0080-\u00FF]/g, "_" );
"____ ______-______. ____ _____ ___ _____! __ _____, __ _____ __ ____. __ _____ ~_____. _____, _____ ____ _'_____. ____ _____ __ _____. _______, ___ ____ ____! _______."
Thanks!