We are trying to figure out if there is a way to find and replace a "\n" string with the character "-" (hyphen).

Excel does a great job finding and replacing all, but not sure how to do same function in QGIS.

enter image description here

Note that the attribute table contains about 1000 of these strings so it would have to be a function that would look within the string for the \n characters without having to input the specific string by hand, if that makes sense.


1 Answer 1


You can try with this expression in the field calculator:

regexp_replace( "yourfield", '\\\\n', '-')

This sould replace all the \n substrings with -.

  • Why are there four slashes before the 'n' ?
    – csk
    Oct 12, 2017 at 19:05
  • 1
    @csk I can't give you a detailed explanation, but long story short: in regular expressions, \n must be escaped as \\n; in addition, all \ must be escaped as \\ in QGIS regex engines. So 4 backslashes at the end of the story ;)
    – ArMoraer
    Oct 13, 2017 at 5:52

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.