I’m labeling airport taxiways. The taxiway labels are all strings but they tend to be one of three varieties and I would only like to show one of those. I’ve been trying to mess around with Rule-Based Labeling for this layer and haven’t had any success yet.

The strings can be one of the following format:

  1. A, B, C...AA,BB,CC… A1, B1 etc
  2. A.B, A.B.C, A1.B2.A, etc <— the use of the “.” In these makes them different from the first variety
  3. $UNK<— this is when the feature has no known value but the field must still be filled in

Below I've attached an example of what the labels look like in QGIS. enter image description here

I would like to only show the labels of the first variety. I think the best way would be to create a rule that doesn’t print anything that equals $UNK or has “.” in it. I’m just unsure of how to write that as a rule or even if rule-based labeling is the right way to achieve my goal.

2 Answers 2


In the label expression settings you can set up a case statement that basically states

when label in ('list', 'of', 'values', 'to', 'omit') then '' 
else 'label_column' 

You wouldn't need to set a rule for every pattern you want to omit, and you can also use LIKE statements as well, which would extend the above to something like:

when label_column in ('list', 'of', 'values', 'to', 'omit') then '' 
when label_column like 'BADVALUE%' THEN ''
else 'label_column' 

The case statement is converting all the labels in your IN or LIKE statements to '' (nothing), otherwise, using the existing value in the label_column


To add onto @DPSSpatial's reply you could use an expression as a data-defined override for the 'Show label' option under the Label Rendering tab (see screenshot - click on the circled button and select Edit... then paste one of the below expressions adapted to your data)

enter image description here

A simple expression for your case would be: "label_column" NOT LIKE '%.%' AND "label_column" != '$UNK'

This filters out all labels with a full stop in them as well as any matching '$UNK'

Another approach is to use a regex expression to only match labels that have only alphanumeric characters (which excludes the $ and . characters in the labels you don't want). An example for your case would be: regexp_match("label_column",'^[\\w]+$').

This matches any combination of one or more alphanumeric and whitespace characters ([\\w]+) that are the only contents between the beginning and end of the string (^ and $ in regex)

Your Answer

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

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