Javascript/NodeJS - Regex Pattern needed.
Budget: $10 – $30 USD
Need a regex pattern created. Currently I have this:
function urlEdit(url: string) {
if (url.includes('.test.io')) {
return url
.replace('.test.io', '')
.replace('https://', 'https://newlink.io/test/')
} else if (url.includes('test.io/ipfs')) {
return url.replace('test.io', 'newlink.io')
}
return url
}
I've managed to do this for the first part:
function urlEdit(url: string) {
const regex = new RegExp("(https:\\/\\/)([a-z0-9]*)(.test.io|.othertest.io)(.*)", 'g')
const subst = `$1newlink.io/$2$4`;
return url
.replace(regex, subst)
}
But it doesn't include the second part of the first code. What this regex needs to do in a combine one line RegExp would be:
https://bafybeih5iva72ff4zgx5cj2glg6n4xgmwbxexi3qqxnygr6gqrawdtgsfmx.test.io/1111.txt
OR
https://bafybeih5iva72ff4zgx5cj2glg6n4xgmwbxexi3qqxnygr6gqrawdtgsfmx.othertest.io/1111.txt
CHANGES TO:
https://newlink.io/ipfs/bafybeih5iva72ff4zgx5cj2glg6n4xgmwbxexi3qqxnygr6gqrawdtgsfmx/1111.txt
-
https://test.io/ipfs/bafybeih5iva72ff4zgx5cj2glg6n4xgmwbxexi3qqxnygr6gqrawdtgsfmx/1111.txt
OR
https://othertest.io/ipfs/bafybeih5iva72ff4zgx5cj2glg6n4xgmwbxexi3qqxnygr6gqrawdtgsfmx/1111.txt
CHANGES TO:
https://newlink.io/ipfs/bafybeih5iva72ff4zgx5cj2glg6n4xgmwbxexi3qqxnygr6gqrawdtgsfmx/1111.txt
Is this possible in one go or do I need two REGEXP?
This should be hopefully fairly easy for someone who knows complex REGEXP!
function urlEdit(url: string) {
if (url.includes('.test.io')) {
return url
.replace('.test.io', '')
.replace('https://', 'https://newlink.io/test/')
} else if (url.includes('test.io/ipfs')) {
return url.replace('test.io', 'newlink.io')
}
return url
}
I've managed to do this for the first part:
function urlEdit(url: string) {
const regex = new RegExp("(https:\\/\\/)([a-z0-9]*)(.test.io|.othertest.io)(.*)", 'g')
const subst = `$1newlink.io/$2$4`;
return url
.replace(regex, subst)
}
But it doesn't include the second part of the first code. What this regex needs to do in a combine one line RegExp would be:
https://bafybeih5iva72ff4zgx5cj2glg6n4xgmwbxexi3qqxnygr6gqrawdtgsfmx.test.io/1111.txt
OR
https://bafybeih5iva72ff4zgx5cj2glg6n4xgmwbxexi3qqxnygr6gqrawdtgsfmx.othertest.io/1111.txt
CHANGES TO:
https://newlink.io/ipfs/bafybeih5iva72ff4zgx5cj2glg6n4xgmwbxexi3qqxnygr6gqrawdtgsfmx/1111.txt
-
https://test.io/ipfs/bafybeih5iva72ff4zgx5cj2glg6n4xgmwbxexi3qqxnygr6gqrawdtgsfmx/1111.txt
OR
https://othertest.io/ipfs/bafybeih5iva72ff4zgx5cj2glg6n4xgmwbxexi3qqxnygr6gqrawdtgsfmx/1111.txt
CHANGES TO:
https://newlink.io/ipfs/bafybeih5iva72ff4zgx5cj2glg6n4xgmwbxexi3qqxnygr6gqrawdtgsfmx/1111.txt
Is this possible in one go or do I need two REGEXP?
This should be hopefully fairly easy for someone who knows complex REGEXP!