min read

Find and replace with Regex Capture Groups

A short introduction into the syntax of Regular Expression Groups that can be used for very common data transformation tasks. I personally often need them, when I use data from excel and need to extract something and put it into a list of strings, to use it for example in an SQL query like:

Name Column




select * from MyTable where name in ('A','B','C');

I usually execute them in IntelliJ / DataGrip with `STRG + F` and `STRG + R`. This should open, depending on your defined key mappings a mask like this:

Find-Replace-Mask in IntelliJ



Match text of the whole line from beginning to end


Capture the text of the whole line into a group by adding () to a segment


Capture the text of the whole line into a named group


Adding multiple brackets into the regex will create multiple capture groups.


Get capture by order

First group


Second group


and so on.

Get capture by name



Convert column row entries from Excel to comma-separated strings, for example, to be used for range queries in SQL: