Regex to compare strings with Umlaut and non-Umlaut variations

后端 未结 7 1720
刺人心
刺人心 2021-01-13 10:34

Can anyone help me with a javascript regular expression that I can use to compare strings that are the same, taking into acccount their non-Umlaut-ed versions.

for e

7条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-13 10:46

    I have another way : ( purpose : sorting arrays )

    function umlaut(str) {
     return str
      .replace(/Â|À|Å|Ã/g, "A")
      .replace(/â|à|å|ã/g, "a")
      .replace(/Ä/g, "AE")
      .replace(/ä/g, "ae")
      .replace(/Ç/g, "C")
      .replace(/ç/g, "c")
      .replace(/É|Ê|È|Ë/g, "E")
      .replace(/é|ê|è|ë/g, "e")
      .replace(/Ó|Ô|Ò|Õ|Ø/g, "O")
      .replace(/ó|ô|ò|õ/g, "o")
      .replace(/Ö/g, "OE")
      .replace(/ö/g, "oe")
      .replace(/Š/g, "S")
      .replace(/š/g, "s")
      .replace(/ß/g, "ss")
      .replace(/Ú|Û|Ù/g, "U")
      .replace(/ú|û|ù/g, "u")
      .replace(/Ü/g, "UE")
      .replace(/ü/g, "ue")
      .replace(/Ý|Ÿ/g, "Y")
      .replace(/ý|ÿ/g, "y")
      .replace(/Ž/g, "Z")
      .replace(/ž/, "z"); 
    }
    

提交回复
热议问题