I'm having a drama labelling using RegEx in QGIS.

Ideally, what I want is the lines labelled WITHOUT the 'Spec' in the middle. Which can be a variation of numbers and characters but I need to retain the '1 x' and '24F'

EDIT; 'Spec' can be a variation of characters. e.g 'ABC123' it wont be the word 'Spec'

So the labels will go from this:

  • 2 x Spec - 48F
  • 1 x Spec - 96F
  • 1 x Spec - 12F

To this:

  • 2 x 48F
  • 1 x 96F
  • 1 x 12F

I'm currently using this in the Expression dialog window of the labelling engine;

regexp_replace( "value", (regexp_substr( "value", '[x](.*)?[- ]1')),'')

This works for the multi line values, those with a return. But it eliminates anything on a single line.

I need the single line values as well as the multi line strings.

Any pointers on what I could be missing?

Table Example

Example of labelling using current RegEx

  • 1
    What about replace("value", ' Spec', '') ?
    – pLumo
    Commented Aug 29, 2017 at 8:38
  • Apologies if it's not clear enough, but 'Spec' can be a variation of values - i.e 'ABC12345'
    – Craig
    Commented Aug 29, 2017 at 8:42

1 Answer 1


This expression works on your examples (multi and single lines), on QGIS 2.18.3.

regexp_replace( "value", regexp_substr( "value", 'x( \\S* -)? \\d'), '')

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.