Javascript Regex来标识字符串并删除该字符串的href

Javascript Regex来标识字符串并删除该字符串的href,javascript,jquery,html,regex,Javascript,Jquery,Html,Regex,我想删除“查看幻灯片”的锚定标签。检查幻灯片显示文本是否可以更改。因此,我们必须认同href中的#show gallery var jStr=$('.gallery wrapper').html(); cStr=jStr.Replace(“/#展厅/”,”)

我想删除“查看幻灯片”的锚定标签。检查幻灯片显示文本是否可以更改。因此,我们必须认同href中的#show gallery

var jStr=$('.gallery wrapper').html();
cStr=jStr.Replace(“/#展厅/”,”)

    如果迈克在附近,你可以肯定诺亚就在那里。在他旁边。任何时候。迈克在做什么并不重要。铲土、回收——不管情况如何,诺亚都会“帮忙”

    他崇拜他的爸爸,想做爸爸所做的一切。虽然这对迈克来说并不总是那么方便(因为一个4岁的孩子的“帮助”的想法充其量是值得怀疑的),但它确实在早餐时派上了用场。诺亚很高兴迈克能和我们一起吃早餐,他想吃什么就吃什么。

    幸运的是,迈克是一个非常健康的食客,早上经常吃一大碗燕麦粥。因此,我很高兴有机会品尝。

    了解更多有关麦片早餐的信息

    披露:该职位的报酬和产品由贵格会通过媒体提供。这里表达的所有观点——一如既往——完全是我自己的观点,并不代表贵格会的观点或立场。

尝试用
替换你的
href
,显示你的
html文本
,请参见

var re=/.

\n\n了解有关\'s燕麦早餐的更多信息

披露:该职位的报酬和产品由贵格会通过媒体提供\n这里表达的所有观点——一如既往——完全是我自己的观点,并不代表贵格会的观点或立场。

; 变量subst='$2'; var结果=str.replace(re,subst);

尝试用
#show gallery
替换
href
html文本中,请参阅

var re=/.

\n\n了解有关\'s燕麦早餐的更多信息

披露:该职位的报酬和产品由贵格会通过媒体提供\n这里表达的所有观点——一如既往——完全是我自己的观点,并不代表贵格会的观点或立场。

; 变量subst='$2'; var结果=str.replace(re,subst);

这也是我的例子——是的,它更通用,但它是一个非常简单和必要的工具。多亏了“好奇之心”让我走上了正轨。幸运的是,这在爱奥尼亚项目中运行良好

//只将URL导出为文本-不带链接。
var stringText='是一个伟大的网站';
var stringText=条带链接(stringText);
document.getElementById(“test”).innerHTML=stringText;
//字符串将:酷链接是一个伟大的网站
功能条带链接(文本){

var re=/这也是我的例子——是的,它更通用,但它是一个非常简单和必要的工具。感谢@好奇的心让我从正确的角度出发。幸运的是,这在爱奥尼亚项目中效果很好

//只将URL导出为文本-不带链接。
var stringText='是一个伟大的网站';
var stringText=条带链接(stringText);
document.getElementById(“test”).innerHTML=stringText;
//字符串将:酷链接是一个伟大的网站
功能条带链接(文本){

var re=/方法的名称是
replace
而不是
replace
。JavaScript区分大小写。此外,您应该选择目标
a
元素并修改其属性,而不是重置整个HTML内容。您希望有人为您编写正则表达式,还是我误解了您的问题?是的,我需要帮助h regex。要替换,您是否尝试过编写一个?方法的名称是
replace
而不是
replace
。JavaScript区分大小写。此外,您应该选择目标
a
元素,并修改其属性,而不是重置整个HTML内容。您希望有人为您编写正则表达式,还是让我修改它明白你的问题了吗?是的,我需要关于正则表达式的帮助。要替换正则表达式,你试过写一个吗?
var re = /<a\s.*?href=["']([^"']*?#show-gallery[^"']*?)[^>]*>(.*?)<\/a>/g;
var str = '<div class=\'gallery-wrapper\'><div class=\'knot-slideshow\' data-slideshow-slug=\'oatmeal-with-kids-0\' data-slideshow-id=\'266039\'></div>\n<ul class=\'knot-slideshow-data\' style=\'display:none;\'></ul></div><br><br />\n<p>You know the song "Me and My Shadow"? Well that is exactly the tune that comes to mind whenever I watch Mike and Noah. Literally.\n</p>\n <p>If Mike is around you can be sure that Noah is right there. Next to him. At all times.\n And it doesn\'t matter what Mike is doing. Shoveling, putting the recycling together - whatever the situation, Noah is there to "help".</p> \n <p>He adores his daddy, and wants to do everything Daddy does. And while this is not always so convenient for \n Mike (as a 4-year-old\'s idea of "help" is questionable, at best), it does come in handy at breakfast. Noah is delighted \n when Mike can join us for breakfast, and wants to have whatever he is having.</p> <p>Fortunately, Mike is a very healthy eater, \n and often has a big bowl of oatmeal in the morning. So I was delighted to have the opportunity to sample \n <a href="http://www.quakeroats.com/products/hot-cereals/perfect-portions/maple.aspx">Quaker Perfect Portions</a>.</p> \n <p><a href="http://www.kitchendaily.com/read/eating-oatmeal-with-kids/#show-gallery">Check out the slideshow above</a>\n to learn more about <a href="http://sherisilver.com/2013/05/17/like-father-like-son-sponsored-post/">Donuts, Dresses And Dirt</a>\'\n s oatmeal breakfast!</p> <p>Disclosure: Compensation and product for this post was provided by Quaker, via Media. \n All opinions expressed here - as always - are completely my own, and are not indicative of the opinions or positions of Quaker.<br /> </p>';
var subst = '$2';

var result = str.replace(re, subst);