DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: Help Creating an Alias RegEx with Multiple Optional Parameters  (Read 9,960 times)

CatamountJack

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 56
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
Re: Help Creating an Alias RegEx with Multiple Optional Parameters
« Reply #1 on: December 30, 2008, 01:42 PM »
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
Re: Help Creating an Alias RegEx with Multiple Optional Parameters
« Reply #2 on: December 31, 2008, 09:38 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,277
    • Coding Snacks
    • Volunteers/Staff
    • Gathering Badge
    • Participated in NANY Challenge Once
    • Linux User
Re: Help Creating an Alias RegEx with Multiple Optional Parameters
« Reply #3 on: December 31, 2008, 11:04 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
Re: Help Creating an Alias RegEx with Multiple Optional Parameters
« Reply #4 on: January 02, 2009, 06:46 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:

[attach]
« Last Edit: January 02, 2009, 06:48 PM by CatamountJack »

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,931
    • Gathering Badge
    • Plugin Coding Medal
    • Participated in NANY Challenge Seventeen Times
    • Cody Award
    • Coding Snacks
    • Volunteers/Staff
Re: Help Creating an Alias RegEx with Multiple Optional Parameters
« Reply #5 on: January 13, 2009, 12:43 PM »
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.

Original address: https://www.donationcoder.com/forum/index.php?topic=16375.0