| Level Navigation: 1 | (2ℹ️) | 3 | 4 | 5 | 6 | (7ℹ️) | (8ℹ️) | (9ℹ️) | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | (37ℹ️) | 38⚡ | 39⚡ | 40⚡ | 41⚡ | 42 | 43⚡ | 44⚡ | 45 | 46 | (47ℹ️) |
If we want to replace ALL punctuation (not just specific ones), we can use \W which matches any non-word character:
export function toSnakeCase(text) {
return text.replaceAll(' ', '_').replaceAll(/\W/g, '_').toLowerCase();
}
What does \W do?
\W matches any non-word character (punctuation, symbols, etc.)\w stands for word characters; uppercase \W flips the meaning to non-word characters.g flag makes the regex global so every non-word character gets replacedTry it: Update your function and run your tests. They should still pass!