Reputation: 31
In Notepad++, I'd like to replace only the first and second comma (","), by ":".
Example :
blue,black,red -> blue:black:red (2 first commas replaced)
blue,black,red,yellow -> blue:black:red,yellow (third comma still here)
Thanks!
Upvotes: 2
Views: 3401
Reputation: 174826
Just two capturing groups is enough.
Regex:
^([^,]*),([^,]*),
Replacement string:
$1:$2:
Explanation:
^
Asserts that we are at the start.([^,]*)
Captures any character not of ,
zero or more times and stored it into a group.(ie, group 1),
Matches a literal ,
symbol.([^,]*)
Captures any character not of ,
zero or more times and stored it into a group.(ie, group 2),
Matches a literal ,
symbol.Upvotes: 1
Reputation: 1535
Something along this line,
^([^,]*),([^,]*),(.*)$
And replace with
$1:$2:$3
Or \1:\2:\3
Upvotes: 1
Reputation: 3093
Click on the menu item: Search > Replace
In the dialog box that appears, set the following values...
Find what: ^([^,]+),([^,]+),
Replace with: $1:$2:
Search Mode: Regular expression
Upvotes: 0
Reputation: 6809
I believe you can do this by replacing this regex:
^([^,]*),([^,]*),(.*)$
With this:
$1:$2:$3
For compatibility with cases where there are less than 2 commas, use these:
^(([^,]*),)?(([^,]*),)?(.*)$
$2:$4:$5
Upvotes: 2
Reputation: 22478
A no-brainer; virtually "GREP 1-0-1". Not really an effort.
Just find
^([^,]+),([^,]+),
and replace with
\1:\2:
Upvotes: 0
Reputation: 477533
Well you can try to capture the parts in groups and then replace them as follows:
/^([^,]*),([^,]*),(.*)$/$1:$2:$3
How does it work: each line is matched such that the first part contains all data before the first comma, the second part in between the two commas and the third part all other characters (including commas).
This is simply replaced by joining the groups with colons.
Upvotes: 0