phew Posted November 2, 2007 Share Posted November 2, 2007 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! Link to comment Share on other sites More sharing options...
picaxe Posted November 2, 2007 Share Posted November 2, 2007 Try If ubound($parameter)-1 = 4 then ;do something with 4th parameter endif Link to comment Share on other sites More sharing options...
phew Posted November 2, 2007 Author Share Posted November 2, 2007 TryIf ubound($parameter)-1 = 4 then ;do something with 4th parameterendifdoesn't work for me, but thanks for the suggestion. any other ideas? Link to comment Share on other sites More sharing options...
weaponx Posted November 2, 2007 Share Posted November 2, 2007 Are you using this to parse command line parameters? Link to comment Share on other sites More sharing options...
phew Posted November 2, 2007 Author Share Posted November 2, 2007 (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 November 2, 2007 by phew Link to comment Share on other sites More sharing options...
weaponx Posted November 2, 2007 Share Posted November 2, 2007 If none of the commands contain spaces, you could just do: StringSplit($cmdl[1], " ") Link to comment Share on other sites More sharing options...
phew Posted November 2, 2007 Author Share Posted November 2, 2007 (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 November 2, 2007 by phew Link to comment Share on other sites More sharing options...
phew Posted November 2, 2007 Author Share Posted November 2, 2007 StringRegExp($cmdl[1], '(.*)\s' & Chr(34) & '(.*)' & Chr(34) & '\s([01])\s(-[ns])?', 1) is working, i forgot it needs the whitespaces, too =) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now