简单javascript正则表达式-添加另一个关键字

简单javascript正则表达式-添加另一个关键字,javascript,regex,Javascript,Regex,如何更新此正则表达式以查找和替换“/news/”和“/blog/”呢 很简单。谢谢 我认为应该这样做: urlLinks = $(this).attr("href").replace(/(\/(news|blog)\/)/, "$1article/"); 这样测试: >>> 'http://www.example.org/news/test.html'.replace(/(\/(news|blog)\/)/, "$1article/"); "http://www.exampl

如何更新此正则表达式以查找和替换“/news/”和“/blog/”呢


很简单。谢谢

我认为应该这样做:

urlLinks = $(this).attr("href").replace(/(\/(news|blog)\/)/, "$1article/");
这样测试:

>>> '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"
>>> '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"