I have got a shapefile that contains ESRI formatting tags in the column I want to use for labeling the layer in QGIS. The following is an example for a label of one feature (3 Labels in different colors for one feature):

<CLR red='110' green='110' blue='110'>ST-SUD-VL-03-1</CLR>
<CLR red='0' green='92' blue='230'>ST-SUD-XX-03</CLR>
<CLR red='110' green='110' blue='110'>ST-SUD-XX-02</CLR>

As far as I know there is no support for inline styling in QGIS yet: https://github.com/qgis/QGIS/pull/2856

As it is not possible to use these tags for coloring the labels I would like to get rid of the tags to have a clean column that just contains the text that should appear on the map.

I know how to use 'replace' in the expression builder but haven't found out how use wildcards. For example i want to delete all <CRL> ***</CLR> -Tags but as the color-values are not static I cannot use a static replace-expression.

Any idea how to extract everything between the three opening- and closing- <CLR>-tag?

  • Just tried to answer and then re-read the Q. For your example thats the attribute for one feature and you want the label to read "ST-SUD-VL-03-1 ST-SUD-VL-03-03 ST-SUD-VL-03-02" - ie space separated?
    – Spacedman
    Commented Feb 14, 2017 at 8:28
  • @Spacedman yes, exactly. space separated or with a special character used for line break
    – Thomas B
    Commented Feb 14, 2017 at 8:45
  • 1
    Since your string format is quite fixed, a bunch of nested regexp replaces should do it - sadly I seem to have completelybroken labelling on my QGIS install while messing around with this so I can't do it at the moment! It might also be at the complexity level where writing a new expression in python would be easier.
    – Spacedman
    Commented Feb 14, 2017 at 9:56
  • @markgraeflerland All the code posted (three lines) is stored in the same field and in that way for the current feature?
    – mgri
    Commented Feb 14, 2017 at 10:05
  • @mgri: yes. all stored in one field and for one feature. Some of them have 1 line, some 2 and some 3 lines of labeling-text
    – Thomas B
    Commented Feb 14, 2017 at 10:22

1 Answer 1


As long as there's no more angle brackets in the label string, the expression:

regexp_replace(L, '<[^>]*>','')

should do it, where L is your attribute name. enter image description here

  • that's a great solution as it works for other esri-formatting-tags, too ( desktop.arcgis.com/en/arcmap/10.3/map/working-with-text/… )
    – Thomas B
    Commented Feb 14, 2017 at 11:23
  • I wasn;t expecting it to work because the help talks about it not supporting non greedy regular expressions so I thought it would replace everything from the first < to the last >, thus losing everything, rather than doing several replaces...
    – Spacedman
    Commented Feb 14, 2017 at 11:25

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.