I downloaded OSM .pbf raw data for Germany. Right now I'm trying to create label badges for german highways. German highways have names starting with the letter 'A' followed by a number with up to three digits.

In my dataset the information about the highway name is stored in a column called "other_tags" alongside with other information looking like this:

"bdouble"=>"yes","maxspeed"=>"none","oneway"=>"yes","ref"=>"A 7","surface"=>"asphalt"

I want to extract the 'A 7' diregarding the rest of the string. I thought about using regular expressions to do so (QGIS actually has this feature -> GREAT!), however I'm stuck implementing it without failing.

This is what I've tried using a custom expression for 'Label with':

regexp_substr( other_tags ,'A\s[0-9]+')  

My understanding of the regexp implementation is:

regexp_substr('string to analyze', 'regular expression output')

However, since that does not work I could need some help on building the expression.

1 Answer 1


Try with regexp_substr( "other_tags" ,'(A\\s[0-9]{1,3})') (tested on QGIS 2.14).

The key part are the parentheses (), corresponding to the capturing group.

For some reason, \s does not seem to work, so I replaced it with a simple blank space. As per ndawson's comment, \s simply needs to be escaped (\\s).

I also replaced [0-9]+ with [0-9]{1,3} to fit your criterion ("names starting with the letter 'A' followed by a number with up to three digits").

  • 3
    the "\" in "\s" needs to be escaped - replace it with "\\s" and it'll work.
    – ndawson
    Commented Oct 6, 2016 at 23:31

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.