Using Typescript and Node v8, I am trying to process a markdown text and remove all the image URLs that follow a specific pattern:
- URLs that contain the word forbidden
- URLs with IP addresses
I am trying using this regular expression:
![([^]]+)]((.(fordbidden|(?:[0-9]{1,3}.){3}[0-9]{1,3}).)\
const markdownText =
'\
* \
*  \
*  \
';
const forbiddenImages = /!\[([^\]]+)\]\((.*(fordbidden|(?:[0-9]{1,3}\.){3}[0-9]{1,3}).*)\)/gm;
function removeForbidden(markdown: string): string {
return markdown.replace(forbiddenImages,"![$1] ()");
}
console.log(removeForbidden(markdownText)
I am getting only the first line of the input:
* ![Allowed image] ()
Thanks in advance!