How can I update this regular expression to find and replace not just "/news/" but "/blog/" as well?
urlLinks = $(this).attr("href").replace(/(\/news\/)/, "$1article/");
It's a simple one. Thanks!
How can I update this regular expression to find and replace not just "/news/" but "/blog/" as well?
urlLinks = $(this).attr("href").replace(/(\/news\/)/, "$1article/");
It's a simple one. Thanks!
I think this should do it:
urlLinks = $(this).attr("href").replace(/(\/(news|blog)\/)/, "$1article/");
Tested like so:
>>> 'http://www.example.org/news/test.html'.replace(/(\/(news|blog)\/)/, "$1article/");
"http://www.example.org/news/article/test.html"
>>> 'http://www.example.org/blog/test.html'.replace(/(\/(news|blog)\/)/, "$1article/");
"http://www.example.org/blog/article/test.html"