[GIS] Using “right()” and “strpos()” to get rightpart of string for QGIS Field Calculator

field-calculatorqgis

The strpos() function searches from the left side of the string. But instead of always trimming the string, I would like to get the position from the right side. Is there anyway to do this in the field calculator?

Here is the specific case of application:

enter image description here

I wanted to get the part of the string in "FolderPath" up the first '/' from the right.

Best Answer

I would use regexp_substr instead of strpos so in your example something like:

regexp_substr("FolderPath",'.*/') 

The first item ("FolderPath") is your column name (enclosed in "), the second is a standard python regular expression. There is a regexp howto available to help you out.

Related Question