1

I would like to search for all admin levels with the values between 7 to 11 using the following query (http://overpass-turbo.eu/s/Dn5):

(relation[admin_level~"^[7-11]$"]["wikidata"]({{bbox}});

The error says:

static error: Invalid regular expression: "^[7-11]$"

Surprisingly a search query with ^[3-6]$ works perfectly fine. So it seems to be related to the 2 digit number.

Does anybody know how to improve this query?

0

2 Answers 2

5

Using regular expressions for numeric comparisons is no longer needed since release 0.7.55 and discouraged these days. Instead you can use numeric comparisons like described in the following blog post: http://dev.overpass-api.de/blog/numbers.html

For your example, the respective query should look as follows:

[out:json][timeout:60];
relation[admin_level]
        (if:is_number(t["admin_level"]) &&
                      t["admin_level"] >= 7 && 
                      t["admin_level"] <= 11)
         ["wikidata"]({{bbox}});
out body;
>;
out skel qt;
2
  • Thanks for the hint. But your query also found admin levels smaller than 7. I changed it a bit and it seems to work now: ` [out:json][timeout:60]; relation[admin_level] (if:(t["admin_level"] >= 7 && t["admin_level"] <= 11)) ["wikidata"]({{bbox}}); out body; >; out skel qt; `
    – René K
    Commented Nov 5, 2018 at 18:56
  • 1
    You're right, there was an issue with parentheses after is_number(....)... I fixed that now.
    – mmd
    Commented Nov 5, 2018 at 19:26
0

The [a-b] notation matches a single character in a range, for example [a-z] matching lower case letters.

What you can do for a small range of integers is to spell them out as alternatives. This might work:

//not working (admin level from 7 to 11)
[out:json][timeout:60];
(relation[admin_level~"^(7|8|9|10|11)$"]["wikidata"]({{bbox}});
);
out body;
>;
out skel qt;

but is obviously tedious if you have 100 levels.

There's some info on regexping numeric ranges here: https://www.regular-expressions.info/numericranges.html

9
  • Thanks Spacedman. Just 11 levels, anyway. So the solution is great. This also seems to work: (relation[admin_level~"[7891011]"]["wikidata"]({{bbox}});
    – René K
    Commented Nov 4, 2018 at 22:37
  • I'm not convinced by that - the area in your link in your Q doesnt seem to have any 10 or 11 in it, but if I zoom out a bit I can find some, but the [7891011] doesn't find it properly.
    – Spacedman
    Commented Nov 4, 2018 at 22:39
  • Around Potsdam is an admin_level=11. And the query seems to be able to find it (overpass-turbo.eu/s/Dnc)
    – René K
    Commented Nov 4, 2018 at 22:41
  • Compare overpass-turbo.eu/s/Dnd which matches ^[1011]$ - it finds nothing and overpass-turbo.eu/s/Dne which matches ^10$ and finds areas in the same bounding box.
    – Spacedman
    Commented Nov 4, 2018 at 22:43
  • 3
    Using regular expressions is really the outdated way of doing things, you should use numeric comparisons instead. See dev.overpass-api.de/blog/numbers.html
    – mmd
    Commented Nov 5, 2018 at 12:29

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.