2

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.

underdark
84.9k22 gold badges237 silver badges418 bronze badges
asked Oct 6, 2016 at 14:20

1 Answer 1

6

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").

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.