#19070 closed enhancement (fixed)
SearchCompiler: regexp comparison using <tilde>
Reported by: | simon04 | Owned by: | simon04 |
---|---|---|---|
Priority: | normal | Milestone: | 20.05 |
Component: | Core | Version: | |
Keywords: | search regex | Cc: |
Description
This increases (mental) interoperability with MapCSS and Overpass QL. Also required for #18164
Example: highway~primary|secondary
Attachments (1)
Change History (15)
comment:1 by , 5 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
by , 5 years ago
Attachment: | 2020-04-11-174017_1119x513_scrot.png added |
---|
follow-up: 6 comment:5 by , 5 years ago
The regular expression mode not only affects key=value
queries, but is used for other types as well, see org.openstreetmap.josm.data.osm.search.SearchCompiler#parseFactor()
Since search expressions are also used for user-defined filters, dropping this radio button element sounds like pain to me.
follow-ups: 7 11 comment:6 by , 5 years ago
Replying to simon04:
The regular expression mode not only affects
key=value
queries, but is used for other types as well, seeorg.openstreetmap.josm.data.osm.search.SearchCompiler#parseFactor()
I just wondered what happens when you enable the button AND use e.g. highway~trunk.*
Since search expressions are also used for user-defined filters, dropping this radio button element sounds like pain to me.
+1
BTW: The regex search works a bit strange, no matter which version I use.
highway~trunk finds highway=trunk, but not highway=trunk_link
With highway~trunk.* finds both
When I just search for trunk with "standard Search syntax" enabled I also find both, but also other stuff like highway:historic=trunk or name=Strunk
The search for pattern highway~^trunk.*
doesn't seem to work. I have to use quotes: highway~"^trunk.*"
comment:7 by , 5 years ago
Replying to GerdP:
I just wondered what happens when you enable the button AND use e.g. highway~trunk.*
The radio button is not taken into account when using highway~trunk
highway~trunk finds highway=trunk, but not highway=trunk_link
With highway~trunk.* finds both
The patch is performed using matches()
(in contrast to find()
) – thus the whole string has to be matched against the given regexp. For details see org.openstreetmap.josm.data.osm.search.SearchCompiler.ExactKeyValue#match
follow-up: 9 comment:8 by , 5 years ago
I didn't try to understand the details of the code in SearchCompiler, else I would already have tried to fix #15943.
Looking at your changes in r16260 we probably just have to remove one line?
-
src/org/openstreetmap/josm/gui/dialogs/SearchDialog.java
291 291 .addKeyword("-<i>key</i>:<i>valuefragment</i>", null, tr("''valuefragment'' nowhere in ''key''")), 292 292 GBC.eol()); 293 293 hintPanel.add(new SearchKeywordRow(hcbSearchString) 294 .addKeyword("<i>key</i>", null, tr("matches if ''key'' exists"))295 294 .addKeyword("<i>key</i>=<i>value</i>", null, tr("''key'' with exactly ''value''")) 296 295 .addKeyword("<i>key</i>~<i>regexp</i>", null, tr("value of ''key'' matching the regular expression ''regexp''")) 297 296 .addKeyword("<i>key</i>=*", null, tr("''key'' with any value"))
comment:9 by , 5 years ago
comment:11 by , 5 years ago
Replying to GerdP:
The search for pattern
highway~^trunk.*
doesn't seem to work. I have to use quotes:highway~"^trunk.*"
I searched for peaks with elevation in name. The name:"\\.*\\d+ *m"
query works but name~"\\.*\\d+ *m"
not. According to the help in the search window tilde should work (key~regexp
). Is this intended?
JOSM 16392, regex mode enabled.
comment:12 by , 5 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
comment:13 by , 5 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
- You should compare
foo=bar
tofoo~bar
–foo:bar
is different as it searches for substrings - For matching an arbitrary string you'd use
.*
(without escaping)
Thus, name~"\\.*\\d+ *m"
not matching name=Peak 3000 m
is correct (since \\.*
matches an arbitrary number of dots).
Note: name:"\\.*\\d+ *m"
matches since it searches for substrings – the substring 3000 m
matches
comment:14 by , 5 years ago
@simon04: Ah got it. That escaping confused me. Thanks for the explanation!
In 16260/josm: