Editplus and Regular Expressions
Was converting some excel stock data into csv, and then into mysql insert commands, and needed a quick way to do this.
I’ve always found Edit Plus to be a handy, light weight text editor.. at once stage in life even using it as my main PHP IDE (use ZDE now though).. However today I found out how to do a really cool regular expression search and replace.. Example below:
Say we had the line of data:
1/08/2006,265,87654321
and we wanted it to look like:
INSERT INTO `share_item_history` (`stamp`, `value`, `volume`) VALUES ('2006-08-01',265,87654321);you could do:
Search:
\n
Replace:
\nINSERT INTO `share_item_history` (`stamp`, `value`, `volume`) VALUES ('and then:
Search:
n
Replace:
);\n
and then:
([0-9]*)/([0-9]*)/2006
Search:
2006-\2-\1
It could be done a lot more elegantly using more regular expressions, but I don’t have time right now..
Reference to: http://editplus.info/wiki/Regular_Expressions.
