I am a bit confused about how to do this. I have read alot about string.replace and using the RegExp object but I just can"t figure it out. I keep gettings errors or it just doesnt work. So help me out for understanding how it works in JavaScript.
I person can create a description and I want to fish out some importand words. So I started with regex and got to a point that it works like I intended, but it is only with a static word.
Example:
const value = .. <!-- the description
let tag = .. <-- need this tag to be in the regex
let regex = /(^|\W)abc($|\W)/; <!-- and 'abc' should be replaced with tag
if(value.match(regex)){
// Do something
}
So how can I make the regex replace the 'abc' part with the tag variable?
Thanks already for helping.