Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

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

Login with username, password and session length
  • December 03, 2016, 11:38:34 AM
  • Proudly celebrating 10 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: Help Creating an Alias RegEx with Multiple Optional Parameters  (Read 3518 times)

CatamountJack

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 56
    • View Profile
    • Donate to Member
Help Creating an Alias RegEx with Multiple Optional Parameters
« on: December 28, 2008, 06:32:40 PM »
Hi all,

Perhaps this is more of a general-case regex problem than an FARR problem, but since I'm trying to use it to make FARR work better, I'm hoping someone here might offer some helpful advice...

I have an alias, let's call it "test", and I want to *optionally* pass one or more parameters to it, separated with a space.
-- If I knew there was always going to be one parameter, I might use ^test (.*)
-- If I want that parameter to be optional, I've found that ^test ?(.*)? seems to work just fine
-- But how can I specify multiple optional parameters?

The alias will run a batch file that will handle the optional input.     (batchfile.bat $$1 $$2 $$3)

I've visited numerous sites over the last couple of weeks that explain how to create/use regular expressions, and I've tried all sorts of combinations, but I've yet to find a solution.

Thanks in advance!




herojoker

  • Participant
  • Joined in 2008
  • *
  • Posts: 124
    • View Profile
    • Donate to Member
Re: Help Creating an Alias RegEx with Multiple Optional Parameters
« Reply #1 on: December 30, 2008, 07:42:17 AM »
You first have to specify which content $$1, $$2 etc. may have. Is it possible that they also contain spaces?

CatamountJack

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 56
    • View Profile
    • Donate to Member
Re: Help Creating an Alias RegEx with Multiple Optional Parameters
« Reply #2 on: December 31, 2008, 03:38:19 AM »
Hmmmm.....

In the instances I'm planning on using this for, $$1, $$2, etc would be just short words (perhaps numbers).  In my case, there would be no spaces within each of those arguments since I want to use spaces as the separators between arguments.  I'm not sure whether the batch file I'm passing these to would complain if there were extra spaces included at the beginning/end of each argument or not - I just tried testing it but my computer is having some other serious issues at the moment.

Thanks!

lanux128

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 6,258
    • View Profile
    • Coding Snacks by Lanux128
    • Read more about this member.
    • Donate to Member
Re: Help Creating an Alias RegEx with Multiple Optional Parameters
« Reply #3 on: December 31, 2008, 05:04:22 AM »
among Farr's default alias, there is one for nircmd command-line utilities where multiple parameters are used. you can take a look and try to figure out. also if you can post a screenshot of your alias config window, then it'd be easier to make a suggestion.

CatamountJack

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 56
    • View Profile
    • Donate to Member
Re: Help Creating an Alias RegEx with Multiple Optional Parameters
« Reply #4 on: January 02, 2009, 12:46:27 PM »
Well, it turns out I'm just not very bright (and it only took me a month to figure that out!).  Since command line arguments in batch files are delimited by spaces anyway and, in this case, since I'm using spaces to delimit the arguments in FARR, I don't actually need to specify multiple capturing groups in the regex.  The screenshot is how I'm setting this up:

screenshot.png

The first line in the results box allows me to enter an argument, multiple arguments, or even no argument at all.  I realize the way this particular one is set up I don't need $$2.  The second and third lines are pre-defined examples of what the different arguments might look like.

My question does still stand, however, if I were to use something other than spaces to delimit the different arguments.  I think this would also be useful in the case of czb's Table Data Search plugin, where (if I understand it right) you currently need to create a specific regex to match the data you are filtering.  (e.g. if you are filtering on 4 columns of data, you need to create a regex with 4 capturing groups.)

So, my question is - how can I create a regex that will allow me to enter an arbitrary number arguments (bonus points if it also allows you to use a variety of delimiters).  In the case of my alias above, I might not want to enter any arguments, or maybe I want to enter 1, or 2.  In the case of the Table Data Search plugin, there could be more.  Is there a way to create a regex that is flexible enough to do this?

@lanux128:  Thanks for the suggestion, but from what I can see, while the nircmd aliases do use multiple arguments, the user needs to fill them all in to make the alias work - so that's a bit different than what I'm looking for.

Thanks!
« Last Edit: January 02, 2009, 12:48:39 PM by CatamountJack »

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 36,405
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: Help Creating an Alias RegEx with Multiple Optional Parameters
« Reply #5 on: January 13, 2009, 06:43:56 AM »
im not sure there is a good way to do this with regex.. which is why im thinking i should offer an alternative way of specifying these kinds of arguements are desired.