Regex, Find Replace

Working on a list of data that was 5,000 lines long I discovered that I needed to reorganize the way the list was formatted. Doing this manually would have taken a long time, but luckily the editor I use for programming, NetBeans, has a Search/Replace facility that accepts regular expressions.

Not as easy as it sounds, since RegEx can be difficult to work with, I finally came up with this

INSERT INTO dg_surname VALUES \(.*\, '(.*)'\);

to rework my list that looks like this:

Using RegEx

Using RegEx

The slashes are there to allow special characters to be used as normal characters.
The brackets without slashes have a special meaning allowing me to replace with $1 or $2 or $3 depending on how many brackets I use. The contents of the brackets get put in the var $.

This saved me a few hours of work.

For a quick cheatsheet on regex check here.

This entry was posted in Uncategorized and tagged . Bookmark the permalink.

Leave a Reply