0

i'm trying to do a simple string replace using the code and function below, but for some reason å ä ö gets replaced with nothing (not even a space).

I would like å and ä to be replaced by "a" and ö by "o"...

"ål öl är" becomes: "l-l-r" Any ideas?

let context = 'ål öl är'

const slugify = str =>
  str
    .toLowerCase()
    .trim()
    .replace(/[^\w\s-]/g, '')
    .replace(/[\s_-]+/g, '-')
    .replace(/^-+|-+$/g, '')
    .replace(/[åä]/g, 'a')
    .replace('ö', 'o');


let slug = slugify(context);

console.log(slug);
pilchard
  • 12,414
  • 5
  • 11
  • 23
Toothfairy
  • 383
  • 1
  • 6
  • 24
  • 3
    The `\w` "word character" pattern does not match those characters. Thus your first `.replace()` call gets rid of them. – Pointy Mar 11 '23 at 13:44

0 Answers0