javascriptregexregex-negation

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


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?


Solution

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

    /(?!^)l/g
    

    See if online: jsfiddle