I've matched a string successfully, but I need to split it and add some new segments to URL. If it is possible by regex, How to match url and extract two strings like in the example below?
Current result:
["domain.com/collection/430000000000000"]
Desired result:
["domain.com/collection/", "430000000000000"]
Current code:
var reg = new RegExp('domain.com\/collection\/[0-9]+');
var str = 'http://localhost:3000/#/domain.com/collection/430000000000000?page=0&layout=grid';
console.log(str.match(reg));
domain.com/collection/is always a known constant then why not just do"domain.com/collection/430000000000000".split('domain.com/collection/')['http://localhost:3000/#', '430000000000000?page=0&layout=grid']. or["http://localhost:3000/#/", "domain.com/collection/", "430000000000000?page=0&layout=grid"]if you keep the split text.