So for example instead of:
You would match on
^tor (.*) [--(.*)]?
i could not make this to work but i'm really interested in making the filter optional
anyone knows how to solve that ?
Generally "" in regex means any character from within those listed between the square brackets (e.g., "[Ii]gnore [Cc]apitalization [Ii]n [Ww]ords"), so this does not work. To make the second term optional, you really need
^tor (.*) (--(.*))?
But I'm not sure how FARR regexp engine handles nested groups (i.e., "()") as far as assigning them to $$1, $$2, etc. In some regexp implementations there is a way to specify that a particular "()" is being used only for grouping, and not for extraction; not sure if FARR engine supports that. If not, then probably the outer group is assigned to $$2, while the inner group to $$3... so you would have to use $$3 in the result filter box.EDIT:
Ah, found it through experimentation, FARR using emacs-like syntax... here is what you want:
^tor (.*) (?:--(.*))?
or to answer my original post
^tor(?:rent)? (.*) (?:--(.*))?
In this particular regex syntax "(?:foo)" means "group foo, but do not extract to a positional parameter". Thus "tor(?:rent)?", for example, means match either "tor" or "torrent", and if the latter, don't let it affect the meaning of $$1, etc.EDIT#2:
Oops, the latter part, the alias filtering doesn't work because regex engines are greedy and thus the first "(.*)" always matches everything, including any "-- whatever bits here". It's tricky to do this cleanly. The workaround I came up with, which is a bit kludgy, is to use:
^tor(?:rent)? (?:(.*) -- (.*)|(.*))()
and then modify the torrent search engine invocations to something like
Mininova | http://mininova.org/search/?search=
Note the $$1$$3 instead of just $$1.
This part is the same as before.
(?:(.*) -- (.*)|(.*))
Either match strings of form "xxx ... -- yyy ..." or, if not possible (i.e., "--" does not exist), match everything else.
The outer "(?: ...)" groups the expression, limiting the scope of the "|", but does not cause parameter extraction itself.
The problem with this, and the ugliness, is that in the case where "--" is absent and the second case is used, that last "(.*)" is assigned to $$3, and not $$1; hence the need for "$$3$$1".
the trailing "()"
This is necessary in the case where "--" is present, since in this case the last "(.*)" is not used, and thus $$3 does not exist; what ends up happening is that "$$3" is left verbatim in the invocation string. This extra "()" thus causes $$3 to exist (and be empty) in this scenario; in the alternate case it simply generates a blank $$4.
Oof. Ugly, I know, but it works. A greater regex master than I needs to tell us what the proper way of doing this is, if it is even possible to do cleanly.