Windows – Looking for a regular expression to work on a list of comma separated values

regexshell-scriptultraeditwindowswindows 7

I have line of 3 long numbers separated by comma.
What I want to do is to delete the number in the middle, and leave only first number and last number separated by a comma.



Desired result:


I tried doing this, but it didn't work with these regular expressions:

  • regular expression to find string: %[0-9]+,[0-9]+,[0-9]+
  • regular expression to replace string: ^1,^2

Which regular expression actually does what I want to achieve?

Note – I'm currently using an application called Ultraedit that runs on Windows 7, if you recommend a better text editing application for Windows that can solve my problem please let me know.

Best Answer

You can simply replace the middle number of each line with nothing.

In the editor

That is, in your editor, search-and-replace the regex


(which only matches numbers with commas on both sides, which for your input is just the middle number) with a single comma:


I assume Ultraedit supports regex search-and-replace. If not, try Notepad++, which I know does.

From the command line

Since you tagged your question , here's how to do it from the command-line.


Use sed, a standard Linux command also available for Windows as part of Cygwin or GnuWin32:

C:\>sed -e 's/,[0-9]+,/,/g' filename.txt


Jens pointed out that you can also do it in Windows Powershell; see this explanation.