Possible Duplicate:
how to replace last occurence of a word in javascript?
I have a string, for example: “345,456,678,345,345,678343,232″
I need to remove the last occurring of 345 (in this example in the middle but can be nay where in the string) from the string. Thought about using RegEx but can’t find the right pattern and couldn’t find the solution anywhere.
Can any one help with this?
p.s. I know i can use JavaScript string manipulation for this, but I think that this is what RegEx for…
Thank you…
Erez
Modified from the top answer of how to replace last occurrence of a word in javascript?:
This uses the greediness of
.*— it will try to grab as much of the string as possible, including instances of the desired target, until it reaches the last instance of the target. So, the whole regex matches the entire string up to and including the last instance of the larget, and then replaces it with the matched(.*)which is everything before the target string.