Removing one occurance of a sub string from a string using RegEx in JavaScript -


possible duplicate:
how replace last occurence of word in javascript?

i have string, example: "345,456,678,345,345,678343,232"

i need remove last occurring of 345 (in example in middle can nay in string) string. thought using regex can't find right pattern , couldn't find solution anywhere.

can 1 this?

p.s. know can use javascript string manipulation this, think regex for...

thank you... erez

modified top answer of how replace last occurrence of word in javascript?:

function removelast(str, target) {     return str.replace(new regexp("(.*)"+target), "$1"); } 

this uses greediness of .* -- try grab of string possible, including instances of desired target, until reaches last instance of target. so, whole regex matches entire string , including last instance of larget, , replaces matched (.*) before target string.


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -