H
H
Habr2019-05-28 23:26:09
Regular Expressions
Habr, 2019-05-28 23:26:09

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

2 answer(s)
D
dollar, 2019-05-28
@GA_Roman

var str = "test.example.com";
var pat = "*.example.com";

pat = '^'+pat.replace(/\./g, '\\.').replace(/\*/g,'.*')+'$';
console.log(!!str.match(pat)); //true

I
Ihor Bratukh, 2019-05-28
@BRAGA96

url module

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question