Sign in to follow this  
Followers 0
phew

StringRegExp() 4th parameter

8 posts in this topic

hi!

i have created following regexp:

$parameter = StringRegExp($cmdl[1], '(.*?)' & Chr(34) & '(.*)' & Chr(34) & '(.*?) (-[ns]{0,1})', 1)

so i get an array with 4 values, $parameter[0], $parameter[1], $parameter[2], $parameter[3], ie:

$cmdl[1] = "hellothisis justatest xyz -n"

so:
$parameter[0] = hellothisis
$parameter[1] = justatest
$parameter[2] = xyz
$parameter[3] = -n

but now i want the StringRegExp() also match when the 4th parameter, the -n OR -s is not in the string, so when the 4th parameter is optional:

$cmdl[1] = "hellothisis justatest xyz"

so:
$parameter[0] = hellothisis
$parameter[1] = justatest
$parameter[2] = xyz
$parameter[3] =                <------ empty, " "

how do i do that? the regexp i use (the one above) does only match when -n or -s is specified, but not if i have no -s or -n.

help please!

Share this post


Link to post
Share on other sites



Try

If ubound($parameter)-1 = 4 then

;do something with 4th parameter

endif

Share this post


Link to post
Share on other sites

Try

If ubound($parameter)-1 = 4 then

;do something with 4th parameter

endif

doesn't work for me, but thanks for the suggestion. any other ideas?

Share this post


Link to post
Share on other sites

Are you using this to parse command line parameters?

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Are you using this to parse command line parameters?

no its for my irc channel service bot, im using this to parse commands like !mode #chan +mnst -force Edited by phew

Share this post


Link to post
Share on other sites

If none of the commands contain spaces, you could just do:

StringSplit($cmdl[1], " ")

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

If none of the commands contain spaces, you could just do:

StringSplit($cmdl[1], " ")

this won't work either, because my second parameter can have spaces in it and so this would be split, too

EDIT:

to make it more clear:

i am looking for a way to make a group in a regexp, ie. (.*?) optional. so if there is a group like (.*?) in the string the regexp matches and if there isn't the regexp matches, too. in other programming languages it's often '\' used for that, like \(.*?\) to make the whole group "optional". there must be smtn similiar in au3, too, i'm sure

Edited by phew

Share this post


Link to post
Share on other sites

StringRegExp($cmdl[1], '(.*)\s' & Chr(34) & '(.*)' & Chr(34) & '\s([01])\s(-[ns])?', 1)

is working, i forgot it needs the whitespaces, too

=)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0