rndusr / stig

TUI and CLI for the BitTorrent client Transmission
GNU General Public License v3.0
554 stars 24 forks source link

Can we have regex, please? #229

Closed The-Sound closed 1 year ago

The-Sound commented 1 year ago

Hi! This is more a request than an issue.

I was trying to filter some torrents with the format Name 101-200

I thought that as we have & and | and using ~ for literal strings, I could use *, ? or . to filter them, something like Name ?01-?00 (my use of regex is bad at best, so don't mind that if that's not the issue, sorry) but I was wrong.

It would be too hard to add? Seems like a nice thing to have, thank you.

rndusr commented 1 year ago

Regular expressions are already implemented. This should work:

$ stig ls '=~S\\d+' -c name

It's documented here:

$ stig help filtersmanual
The-Sound commented 1 year ago

Sometimes I'm a little bit dense, but the bit that in theory covers regex would be this one?

  Besides the usual operators (=, !=, >, <, >=, <=), "~" matches if the item's value contains the
  literal string VALUE and "=~" matches if the item's value matches against the Perl-style regular
  expression VALUE.
  Example: "name~foo" matches all torrents with "foo" in their name.

Just asking because I've read a few times that help before opening another issue but maybe I missinterpreted it. Should I go to Perl docs in search of more examples then?

Edit: I'm trying to use it from the inside prompt on an empty tab but I don't think I'm typing it the right way. How would it be from the inside? I don't really use stig from outside itself because my remote instance has password and stuff.

Edit 2: Do you mind if I ask for a little more clarification? I've managed to make the filter work with :list name=~'\\d01-\\d00' and :list name=~'Name \\d01-\\d00' but I'm not entirely sure I got the hand of it, because if I need to seek something that is not exactly Name I don't know how to tell the command "Name, Anything after Name and then \\d01-\\d00"

Edit 3: Sorry for so many edits, seems like all in all, it was my regex skills, although I still think, to my taste, that a quick regex example could be added to filtermanual for brick-dense users like me. Made it work with :list name=~'.\\d01-\\d00'

rndusr commented 1 year ago

I agree that there's room for improvement, but stig is not the place to document regular expression syntax.

The exact implementation used by stig is documented here: https://docs.python.org/3/library/re.html