regex - Javascript: using a wildcard character with a replace method - Stack Overflow

I have a String that contains a line of html code eg. '<b>1995<b>'. Let's s

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 badges
Add a ment  | 

1 Answer 1

Reset to default 7
first_string.replace(/<b>(19\d{2})<\/b>/g, '$1')

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745414520a4626683.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信