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 =
'\
* ![Allowed image](http://accepteddomain/image.png)\
* ![Forbidden domain image](http://fordbidden/image.png) \
* ![Forbiden IP image](http://80.11.20.15/image.png) \
';
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!