I'm working with Javascript and would like to have a regex to find an exact match of a word, I usually could do this:
const regex = new RegExp(`\\b${word}\\b`, "gm");
Where word comes from an array, however with this expression \bsé\b, with this block
no lo sé muy bien
casé
sénégal
Is not working as expected, does regex has any special issue with letters with accent marks? What is the approach I should take?
Thanks!
POST-EDIT: Given regex won't support accents by default, I ended up doing this
function enhanceRegex(word) {
const accents = ["á", "é", "í", "ó", "ú"];
return accents.includes(word.toLowerCase().slice(-1))
? `\\b${word}(\\s|!|\\?|\\.|,|;|:)+(\\b)?`
: `\\b${word}\\b`;
}
basically, I'm adding the most common scenarios I'll have for my texts, probably is not the best but it helps.