DannyLondon
Programmer
Hello All
I have wracked my brain trying to understand regular expressions and trying to solve a problem that I do not believe should be difficult. Alas, I have still not found a solution.
I have the following two strings, which are defined at run time:
var pet = "dog"
var animals = "dog 1;cat 3;horse 1;lion 2"
I would like to replace the "dog 1;" in the second string with an empty string, based on the fact that "dog" is in the first string. I know each animal will be separated by a semi-colon, but don't know what will be between the animal and the semi-colon. In pseudo code, this would be:
var result = animals.replace(pet + "*;", ""
Painfully, I cannot find the code for this pseudo-code. Any help that people could offer would be greatly appreciated.
Thanks, Danny...
I have wracked my brain trying to understand regular expressions and trying to solve a problem that I do not believe should be difficult. Alas, I have still not found a solution.
I have the following two strings, which are defined at run time:
var pet = "dog"
var animals = "dog 1;cat 3;horse 1;lion 2"
I would like to replace the "dog 1;" in the second string with an empty string, based on the fact that "dog" is in the first string. I know each animal will be separated by a semi-colon, but don't know what will be between the animal and the semi-colon. In pseudo code, this would be:
var result = animals.replace(pet + "*;", ""
Painfully, I cannot find the code for this pseudo-code. Any help that people could offer would be greatly appreciated.
Thanks, Danny...