Ruth
Ruth

Reputation: 5816

Javascript: using a wildcard character with a replace method

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

Upvotes: 2

Views: 3164

Answers (1)

SilentGhost
SilentGhost

Reputation: 319821

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

Upvotes: 7

Related Questions