views:

114

answers:

4

I am trying to replace all German special characters in a Regular Expression. The Characters are ä ö ü ß

A: 

Regxr can help you write one. Try this:

RegExp: /\bäöüß\b/gi

pattern: \bäöüß\b

There are a number of ways to apply the actual replacement depending on the language or situation you are in.

Moshe
+1  A: 

I don't think you can do all 4 (or 7) replacements with a single regexp. It's fairly easy, thought, to do it with 4 (or 7) regexps.

Update

Additionally, as Mic has indicated, regexps can be part of the solution but need to be part of some kind of replacing mechanism. More input needed here.

Carl Smotricz
Oh wow, my non-answer has been accepted. Glad I could help!
Carl Smotricz
A: 
/ä/ae/

If Carl is correct about what replacements you're talking about, that'll do; but regexs are not really required here, it can be done with a simple string function/methods.

Of course, for each character you'd need to write new regex.

If you wanted to replace them all with a single character, e.g., a question mark (?), you could use the following regex:

/[äöüß]/?/ig
SilentGhost
Like Mic and I said, it depends on the language. We need to know what language is being used here.
Moshe
What depends on the language? Ability to write regex that'll do some intelligent replacement?
SilentGhost
No, the exact code for replacement. The question was *how to* and that can't be exactly posted without more info.
Moshe
I think *how* is secondary to *what*. OP hasn't given any indication of what is he actually doing.
SilentGhost
A: 

If you want to replace each of those characters with a different character, you'll need four regexes:

/ä/X1/
/ö/X2/
/ü/X3/
/ß/X4/

where X1-X4 are the four replacement characters

OR, if you want to replace any occurrences of those characters with a single character:

/[äöüß]/X/

where X is the replacement character.

The exact regex syntax may different, depending on the programming language.

Donnie DeBoer