Link to home
Create AccountLog in
Avatar of lconnell
lconnell

asked on

RegEx N'th Occurrence using Sublime

I have already asked a similar question here: Regex

I have this regex working within VI which replaces the 3rd occurrence of ',' with 'Unique,'
s/,.\{-},.\{-}\zs,/Unique,

Open in new window


I can't seem to get it to work within Sublime Text Editor. I have tried the following regex, but it doesn't replace the 3rd comma, it instead captures it and places it into my replacement string.

Sample Data: echo "clientRequests#300#raw,$EPOCH_TIME,$_importExternalEmailData,proj_ott,ottcore
Regex Find: (,.*?,.*?,)
Replace Str: $1Unique

I want to find the 3rd comma so I can append to the name $_importExternalEmailData so the result is $_importExternalEmailDataUnique. Right now it will put 'Unique' after the 3rd comma.
ASKER CERTIFIED SOLUTION
Avatar of Terry Woods
Terry Woods
Flag of New Zealand image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
(?=,) is a positive lookahead, which requires the following character at that point to be a comma, but doesn't capture it as part of the match. If that's too scary, you could also just put the comma back in as part of the replacement, with:

Find:
(,.*?,.*?),

Open in new window

Replace:
$1unique,

Open in new window

Avatar of lconnell
lconnell

ASKER

Great, thank you!!