houssam Lemhamdi
houssam Lemhamdi

Reputation: 49

regex replace multiple string in the same time

i want to replace 2 string by 2 values in some time. when i do this.

date1="Date (1995,12,17)"
this.formControlValue=this.formControlValue.replace(/\$RepStartDate/i,date1)

it work perfectly. but when i do this:

this.formControlValue=this.formControlValue.replace(/\$RepStartDate/i,date1)
this.formControlValue=this.formControlValue.replace(/\$RepEndDate/i,date2)

just the first string is replaced,the other string is not converted. how can i replace 2 string in some time?

Upvotes: 1

Views: 151

Answers (1)

Talg123
Talg123

Reputation: 1506

easily:

this.formControlValue=this.formControlValue.replace(/\$RepStartDate/i,date1)
.replace(/\$RepEndDate/i,date2)

replace() return string you can replace it again.

Upvotes: 1

Related Questions