How to replace all BUT the first occurrence of a pattern in string

dr jerry picture dr jerry · Oct 31, 2011 · Viewed 21.6k times · Source

quick question: my pattern is an svg string and it looks like l 5 0 l 0 10 l -5 0 l 0 -10 To do some unittest comparison against a reference I need to ditch all but the first l I know i can ditch them all and put an 'l' upfront, or I can use substrings. But I'm wondering is there a javascript regexp idiom for this?

Answer

Mark Byers picture Mark Byers · Oct 31, 2011

You can try a negative lookahead, avoiding the start of the string:

/(?!^)l/g

See if online: jsfiddle