I need to write a JS RegExp that will match word based on the exclusion of set chars: [', ", -, _ ]
so bolded words should be matched only from my example:
Milan some word, milan again.Milan word - again: Milan, milan-milan. Milan-word milan is word.milan mialn . milan's milan"s, milan milan_milan.
Note: I don't want to include spaces, dots, commas, before/after word milan and therefore I need to get result same as I bolded it above.
I need it to work like: \bmilan\b but i need to exclude set of chars so it doesn't match examples like milan-milan and milan's at all.
I tried to make it work: https://regex101.com/r/FGeNlQ/1 but it isn't complete. In this example spaces, dots, etc... are included in matched word and I don't want that.
Sorry if this may be duplicate but i just can't find right answer
EDIT:
code usage:
window.wrapText = (sentence, word, description) ->
regex = "(?:[^\"'`_-]|^)\\b(" + word + ")\\b(?![\"'`_-])"
re = new RegExp(regex, 'gi')
span = document.createElement('span')
span.innerHTML = sentence
Array.from span.childNodes, (node) =>
if node.nodeType == 3
node.nodeValue.split(re).forEach (part, i) ->
add = undefined
if i % 2
add = document.createElement('span')
add.textContent = part
add.setAttribute('class', 'glossary_text')
else
add = document.createTextNode(part)
span.insertBefore add, node
span.removeChild node
span.innerHTML
note: i may have not escaped well 'regex' variable