PLEASE STOP MARKING AS DUPLICATE QUESTION BEFORE YOU POST RIGHT ANSWER FOR ME. This post is not a place where someone is show off his ROUGH search skills on google.
Simple reg exp is not a problem to inject js variable. but what about the complex one like following?
I have a reg expression to check if the URL is from example.com domain.
^(https?:\/\/(.+?\.)?example\.com(\/[A-Za-z0-9\-\._~:\/\?#\[\]@!$&'\(\)\*\+,;\=]*)?)
Now I want to create a function isValidDomainURL(url, domain)
and inside of the function I d like to use above expression replaced example\.com
with domain
How can I create a reg expression using js variable inside of it?