admin管理员组文章数量:1429977
I have a String that contains a line of html code eg. '<b>1995</b>'
. Let's say this String could also contain '<b>1997</b>'
or '<b>1999</b>'
etc. I want to use a replace method to remove the tags but leave the years. Is there a way to implement a wildcard character to do this, something like:
first_string = "First year is <b>1997</b> and second year is <b>1999</b>"
second_string = first_string.replace(/<b>19.*<\/b>/g, 19.*)
Any help would be much appreciated
I have a String that contains a line of html code eg. '<b>1995</b>'
. Let's say this String could also contain '<b>1997</b>'
or '<b>1999</b>'
etc. I want to use a replace method to remove the tags but leave the years. Is there a way to implement a wildcard character to do this, something like:
first_string = "First year is <b>1997</b> and second year is <b>1999</b>"
second_string = first_string.replace(/<b>19.*<\/b>/g, 19.*)
Any help would be much appreciated
Share Improve this question edited Jun 9, 2010 at 15:41 SilentGhost 321k67 gold badges310 silver badges294 bronze badges asked Jun 9, 2010 at 15:33 RuthRuth 5,82612 gold badges39 silver badges45 bronze badges1 Answer
Reset to default 7first_string.replace(/<b>(19\d{2})<\/b>/g, '$1')
本文标签: regexJavascript using a wildcard character with a replace methodStack Overflow
版权声明:本文标题:regex - Javascript: using a wildcard character with a replace method - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745414519a2657619.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论