[GIS] Extracting text within parenthesis in a QGIS attribute table

qgisregex

I have a shapefile of data for Japan, and I need to extract the English character names in my "name" field in order to label the layer. Much of the data is all in Japanese, but some of the names have an alternate English name which can be found inside a set of parenthesis. I'd like to extract this text to another field and use it for labeling. I'm using QGIS.

Example:

I need to turn

野川サイクリング道路 (Nogawa Cycling Road)  

Into

Nogawa Cycling Road

I'm attempting to use the regexp_substr function in the Field Calculator:

regexp_substr( "name", '\((.*?)\)')

When I try to run this, I get an error:

An error occured while evaluating the calculation string: Invalid regular expression '?(.*?)?': bad repetition syntax.

Oddly, in testing, I tried this same regex in PostGIS and it worked great. Does anyone know of a regex that will do this task in the QGIS field calculator?

Best Answer

I tried this, and it seems to work..

regexp_substr( "name", '[(](.*)?[)]')

You need to use greedy matching (hence the ?), but also need to put square brackets around the round brackets.