QGIS – How to Replace All But Coordinates from a WKT String, Including Closing Bracket ‘)’

expressionqgisregular expressionstring

To get a list of coordinates from a polygon and remove unwanted parts from the resulting string, the following expression works fine to remove the string elements 'Polygon', spaces and opening brackets (:

regexp_replace(
    geom_to_wkt($geometry), 
    '(Polygon)( )(\\(*)',
    ''
)

However, I struggle to find a way to similarily remove closing brackets ). To remove only these brackets, this regex works fine: '(\\))'. But when I add this as another capturing group in line 3 of the expression like '(Polygon)( )(\\(*)(\\))', nothing is replaced at all.

How can I remove all unnecessary characters, including closing brackets? For context, see here.

Best Answer

Other solution:

regexp_replace(
     geom_to_wkt($geometry),
    '(Polygon \\(\\()(.+)(\\)\\))',
    '\\2')

enter image description here

Related Question