topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Wednesday December 11, 2024, 8:50 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: $$c for $$2 or another regular expression?  (Read 8393 times)

herojoker

  • Participant
  • Joined in 2008
  • *
  • Posts: 124
    • View Profile
    • Donate to Member
$$c for $$2 or another regular expression?
« on: August 28, 2008, 01:06 PM »
To reach some flexibility, I set up several different spellings for the same command, for example
^(vid|vids|video|videos) (.*)
as a regular expression pattern. Then I use $$2 to access the entered text in the actual commands.
Now I've found $$c which takes the clipboard text if $$1 is empty and $$1 otherwise. Unfortunately this is not so helpful in that situation.

Is there a $$c - like expression for $$2, $$3 etc.? If not, how could I rewrite the expression to have the actual user input stored in $$1?
-> What I really need is just another pair of grouping brackets which is not a capturing group.

d4ni

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 129
    • View Profile
    • Donate to Member
Re: $$c for $$2 or another regular expression?
« Reply #1 on: August 28, 2008, 01:18 PM »
You can use (?:regex) to use a non-capturing group.

In your case ^(?:vid|vids|video|videos) (.*)

herojoker

  • Participant
  • Joined in 2008
  • *
  • Posts: 124
    • View Profile
    • Donate to Member
Re: $$c for $$2 or another regular expression?
« Reply #2 on: August 28, 2008, 01:44 PM »
Thanks!
Is this documented somewhere?

d4ni

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 129
    • View Profile
    • Donate to Member
Re: $$c for $$2 or another regular expression?
« Reply #3 on: August 28, 2008, 02:06 PM »
I got it off regular-expressions.info, here.

herojoker

  • Participant
  • Joined in 2008
  • *
  • Posts: 124
    • View Profile
    • Donate to Member
Re: $$c for $$2 or another regular expression?
« Reply #4 on: August 31, 2008, 11:28 AM »
Your hint worked - but what if I want to access the non-captured groups in the "Result Filter for RegEx"?

Example:
What I want:
a) Typing wiki should result in the following aliases being shown: Wikipedia (Deutsch), Wikipedia (English), Wiktionary (Deutsch), Wiktionary (English), Wikiquote (Deutsch), Wikiquote (English), ..., Wikimedia
a²) Typing wikt should show only the Wiktionary entries.
b) These aliases should be directly accessible when typing wiki (no space after it), which means that every entry can be activated without having to enter a group (which would require pressing enter twice in total)
c) If no argument is manually entered ([space]+words), the last selected or copied text should be used
d) Adding more characters, e.g. a p should narrow the displayed aliases (e.g. to the two Wikipedia entries)
e) The original order of the entries should be preserved

Examples: In the following "foobar" is in the clipboard. _ is used to display the space character at the end of inputs.

1) wikipediaX, wikipX show normal file/alias search for wikipediaX, wikipX
2) wiki, wiki_ show all wiki-related aliases with foobar as argument
3) wiki baz shows all wiki-related aliases with baz as argument

4) wikip, wikipe, ..., wikipedia, wikip_, wikipe_, ..., wikipedia_ show both Wikipedia entries with foobar as argument
5) wikip baz, wikipe baz, ..., wikipedia baz show both Wikipedia entries with baz as argument

6) wikt, wikti, ..., wiktionary, wikt_, wikti_, ..., wiktionary_ show both Wiktionary entries with foobar as argument
7) wikt baz, wikti baz, ..., wiktionary baz show both Wiktionary entries with baz as argument


The alias lines currently look like this:
Wikipedia (English) - $$c | htmlviewurl http://en.wikipedia....l:Search&search=$$c /ICON=icons\wikipedia.ico

What I tried:
1. One big alias group called wiki
1.1 With regular expression ^wiki (.*)  ->  a), b), c) OK but d) does not work.
1.2 With regular expression ^(?:wiki|wikipedia|wiktionary|wikiquote|wikibooks|wikiversity|wikinews|wikimedia) (.*)  -> a), b), c) OK but d) does not work completely. Typing wikiquote does show results but it shows all results. Not using (?:...) would result in $$1 being used which would make $$c unusable, therefore c) unfulfilled.

2. Many small alias groups "wikipedia", "wiktionary", "wikiquote", "wikibooks", "wikiversity", "wikinews", "wikimedia". With regular expression ^(?:wiki|wikipedia) (.*), ^(?:wiki|wiktionary) (.*) etc.  -> Typing wiki hides the wiktionary alias group -> unacceptable

3. Many small alias groups, all called "wiki"
3.1 Using regular expressions like ^wiki(?:pedia|pedi|ped|pe|p)? (.*), ^wik(?:i|t(?:ionary|ionar|iona|ion|io|i)?) (.*)  -> a), b), c) OK but d) does not work
3.2 Using regular expressions like ^wiki(?:pedia|pedi|ped|pe|p)?\ ?(.*), ^wik(?:i|t(?:ionary|ionar|iona|ion|io|i)?)\ ?(.*)  -> a), b) OK, c), d) almost OK since entering wikiped shows the wikipedia alias with copied text (good) and the wiktionary alias with "ped" as argument.


Do you have any ideas how to realize what I want?

Using "Result Filter for RegEx" hurts requirement e) - I want the results only to be filtered - not sorted.

I think the easiest (and also the most general) solution would be
1. An option (perhaps inline) that the Result Filter does not changes the alias order
2. A function like this: ifempty(variable1, variable2)=variable1 if variable1 is not empty, variable2 otherwise

With this I could simply use a big alias group with the regular expression ^(wik(?:i|t)[^\ ]*)\ ?(.*) and entries using ifempty($$2,$c).
« Last Edit: September 01, 2008, 10:27 AM by herojoker »

d4ni

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 129
    • View Profile
    • Donate to Member
Re: $$c for $$2 or another regular expression?
« Reply #5 on: September 01, 2008, 12:17 PM »
Unfortunately I do not have any experience using the 'Result Filter for RegEx' feature. I hope someone else - like Mouser - can help you :)

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,914
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: $$c for $$2 or another regular expression?
« Reply #6 on: September 01, 2008, 11:28 PM »
if i forget to reply to this in next day or two please remind me -- i just need time to digest it.