I have the following IPFS URL.
https://example.com:2053/ipfs/QmPQeMz2vzeLin5HcNYinVoSggPsaXh5QiKDBFtxMREgLf/images/0000000000000000000000000000000000000000000000000000000000000001.png
I want to use regex to match this file, but instead of writing the full URL, I want to just match something like https*00000001.png.
The problem is that when I use
paddedHex = '00000001';
let tmpSearchQuery = `https*${paddedHex}.png`;
It doesn't really match anything. Why?
You are repeating an s char zero or more times using s* and to create a dynamic regex you have to use the RegExp constructor.
You can repeat optional non whitespace chars instead using \S* and if you want to match http and https make the s optional using s?
const s = `https://ipfs.moralis.io:2053/ipfs/QmPQeMz2vzeLin5HcNYinVoSggPsaXh5QiKDBFtxMREgLf/images/0000000000000000000000000000000000000000000000000000000000000001.png`;
const paddedHex = '00000001';
const tmpSearchQuery = new RegExp(`https?\\S*${paddedHex}\\.png`);
const m = s.match(tmpSearchQuery);
if (m) {
console.log(m[0]);
}