4

I want to replace a '+' with ', ' to label an attribute looking like "ZT10+ZT20+ZT30" to get "ZT10, ZT20, ZT30" using

regexp_replace("zone_nr", '+', ', ')

but I get an Eval Error: Invalid regular expression '+': quantifier does not follow a repeatable item.

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Lukschn
  • 115
  • 5

3 Answers3

10

A + is a special symbol to the QGis regular expression engine (it means 1 or more of the preceding character), so you need to escape it by putting a \ in front of it. So you need:

regexp_replace("zone_nr", '\\+', ', ')
Ian Turton
  • 81,417
  • 6
  • 84
  • 185
9

Or, simply use

replace("zone_nr", '+', ', ')

as this doesn't expect a regexp term (it simply matches all occurences of the specified input string).

geozelot
  • 30,050
  • 4
  • 32
  • 56
2

You can input regular expression to find every single + like [+]

regexp_replace("zone_nr", '[+]', ', ')
Oto Kaláb
  • 6,895
  • 3
  • 29
  • 50