Modify

Opened 8 months ago

Closed 6 months ago

Last modified 6 months ago

#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)

2020-04-11-174017_1119x513_scrot.png (28.8 KB) - added by simon04 8 months ago.

Download all attachments as: .zip

Change History (15)

comment:1 Changed 8 months ago by simon04

Resolution: fixed
Status: assignedclosed

In 16260/josm:

fix #19070 - SearchCompiler: regexp comparison using <tilde>

Changed 8 months ago by simon04

comment:2 Changed 8 months ago by simon04

Updated search dialog:


comment:3 Changed 8 months ago by GerdP

What about the "regular expression" checkbox in the lower left corner?

comment:4 Changed 8 months ago by GerdP

See also #15943

comment:5 Changed 8 months ago by simon04

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.

comment:6 in reply to:  5 ; Changed 8 months ago by GerdP

Replying to simon04:

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()

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 in reply to:  6 Changed 8 months ago by simon04

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

comment:8 Changed 8 months ago by GerdP

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

     
    291291                .addKeyword("-<i>key</i>:<i>valuefragment</i>", null, tr("''valuefragment'' nowhere in ''key''")),
    292292                GBC.eol());
    293293        hintPanel.add(new SearchKeywordRow(hcbSearchString)
    294                 .addKeyword("<i>key</i>", null, tr("matches if ''key'' exists"))
    295294                .addKeyword("<i>key</i>=<i>value</i>", null, tr("''key'' with exactly ''value''"))
    296295                .addKeyword("<i>key</i>~<i>regexp</i>", null, tr("value of ''key'' matching the regular expression ''regexp''"))
    297296                .addKeyword("<i>key</i>=*", null, tr("''key'' with any value"))

comment:9 in reply to:  8 Changed 8 months ago by simon04

Replying to GerdP:

I didn't try to understand the details of the code in SearchCompiler, else I would already have tried to fix #15943.

Let's continue the discussion in #15943 (since it's not related to this ticket).

comment:10 Changed 7 months ago by Klumbumbus

Milestone: 20.0420.05

Milestone renamed

comment:11 in reply to:  6 Changed 7 months ago by gaben

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 Changed 7 months ago by skyper

Resolution: fixed
Status: closedreopened

comment:13 Changed 6 months ago by simon04

Resolution: fixed
Status: reopenedclosed
  • You should compare foo=bar to foo~barfoo: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 Changed 6 months ago by gaben

@simon04: Ah got it. That escaping confused me. Thanks for the explanation!

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain simon04.
as The resolution will be set.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.