Reputation: 2098
There is an input form 7(7**)********, and user enters any digit in any place instead of star(There are 10 stars after 7). For example 7(7**)7**188*8,7(7*0)12****198* or 7(700)123*123*,etc.And then the system should return numbers matching to the input. So,if the input is 7(7**)7**188*8, it should return all the phone numbers which has appropriate numbers in the right place, i.e. 770171318868,776771218858,etc should be returned. I've looked around regex, patterns and match. it seems to be a big topic, could you please direct me to the more exact place?
Upvotes: 1
Views: 43
Reputation: 11116
try this :
var str = "7(7**)7**188*8";
var res1 = str.replace(/[\(\)]/g,'').replace(/\*/g, '\\d');
var re = new RegExp(res1);
console.log(re.test("770171318868"));
console.log(re.test("776771218858"));
Upvotes: 2