I have a string field and I want to delete the part of the string after a specific character in this case a '/'. I am looking for a way to do this using the field calculator in QGIS.

I know I can use the replace function to replace a specific string but I need a way to do this with a wildcard as the strings after the '/' character are not the same in the table.

  • Would you like to remove the / as well?
    – SaultDon
    Commented May 17, 2017 at 23:22

1 Answer 1


You can use a regular expression with the field calculator function regexp_replace() on a NEW field like:

That one will keep the / but if you want the / removed, use: regexp_replace("test_regex",'(/.*$)','')

Explanation: The regular expression being used is /.*$

/ --look for a forward slash

. --identify any character (strings/numbers/special) after the slash except newlines

* --keep searching for any characters after the slash

$ --until the end of the string is reached

  • 1
    Thank you! This worked great and your explanation is very thorough!
    – Ryan Jones
    Commented May 18, 2017 at 14:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.