Answer the question
In order to leave comments, you need to log in
How to replace the asterisk sign with all characters?
How can I replace the asterisk sign with all characters, through a regular expression?
For example: I make a request test.example.com, if the domain is *.example.com, return true
Answer the question
In order to leave comments, you need to log in
var str = "test.example.com";
var pat = "*.example.com";
pat = '^'+pat.replace(/\./g, '\\.').replace(/\*/g,'.*')+'$';
console.log(!!str.match(pat)); //true
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question