Good day! I have a regular season of this kind:
/((^|[\s\.\,\;])(text)($|[\s\.\,\;])|(^|[\s\.\,\;])(textf)($|[\s\.\,\;])|(^|[\s\.\,\;])(texts)($|[\s\.\,\;])|(^|[\s\.\,\;])(textt)($|[\s\.\,\;]))/gi
It consists of almost identical blocks of the form (^|[\s\.\,\;])(text)($|[\s\.\,\;])
which differ only in the forms of the desired word. The regular looks for all occurrences of the word text in various variations (text, textf, texts, textt).
Here is how I use it:
'textf some words texts another words. Textt bla-bla-bla'.replace(/((^|[\s\.\,\;])(textf)($|[\s\.\,\;])|(^|[\s\.\,\;])(texts)($|[\s\.\,\;])|(^|[\s\.\,\;])(textt)($|[\s\.\,\;]))/gi, function() { console.log('"' + arguments[0] + '"'); return '<a>' + arguments[0] + '</a>'; })
console.log(arguments[90])
displays this:
"textf"
"texts"
"Textt"
The very same line after the replacement looks like this:
<a>textf </a> some words<a> texts </a>another words.<a> Textt </a>bla-bla-bla
That is, as you can see the matches found by the regular, include spaces with commas, which in theory should be word boundaries and not participate in the replacement. Obviously, I somehow incorrectly made a regular schedule. I would like the text to be as follows:
<a>textf</a> some words<a>texts</a> another words.<a>Textt</a> bla-bla-bla
Can you please tell me how to change the regular season to achieve this?
/(^ | [\s\.\,\;]) (text | textf | texts | textt) ($ | [\s\.\,\;])/gi
- Pavel Mayorov\b(?:textf|texts|textt)\b
- Visman