Logic : To extend the month validity of a product from 'x' months to 'y' months
ARRAY
from_to[1] = 1 ( this is x )
from_to[2] = 6 ( this is y )
I have some text like this in variable myItem:
Office 1 mo - Rs. 2500/mo
Skype 1 mo - Rs. 1190/mo
Facebook 3 mo - Rs. 1250/mo
I have the following array :
from_to[1] = 1
from_to[2] = 6
I want to count the number of times the value contained in from_to[1] ( i.e. '1') exists in the text. In case of above text it should be '2' times.I want to replace these values with the value contained in from_to[2]
Office 1 mo - Rs. 2500/mo
Skype 1 mo - Rs. 1190/mo
when i am using this code :
var myItem = document.getElementById('itemsdesc').innerHTML;
alert (myItem.match(new RegExp(from_to[1],"gi")).length);
This returns me 5 !! ( i can undertand that it also matches the '1's in the price part ) How to prevent that ?
DESIRED OUTPUT : ( after replacing )
Office 6 mo - Rs. 2500/mo
Skype 6 mo - Rs. 1190/mo
Facebook 3 mo - Rs. 1250/mo
i am a newbie to regex.......