Help with Regexes on Mushclient

by Yoruk

Back to Mechanic's Corner.

Yoruk2009-01-28 23:19:29
This is bothering me very much, i have absolutely no idea why it's not working so if someone could fix this i would appreciate it oh so very much!

I have a trigger:
^Disgustingly, (\\w+) spits at you, hitting you directly in your face\\.$

Alternatively, I've also found the same trigger line in Treant:

^Disgustingly\\, +\\ spits at you\\, hitting you directly in your face\\.$

I want to capture the person's name at (\\w+) and SetVariable('target', %0) but mushclient keeps giving me the error

string "Trigger: affnekospit__"]:1: ')' expected near 'spits'

And nothing i do seems to fix this. There's no open paranthesis i see anywhere that needs to be closed. I'm thinking maybe the regex might've captured ' spits' together which is why the unconcatenated string will cause a problem.

Any help at all is appreciated =]
Thanks!

EDIT: Oh and by the way, I'm working with Lua on MushClient.
EDIT: And i just realized there's a mushclient topic already. Should i move it there?
Isuka2009-01-29 00:21:50
QUOTE (Yoruk @ Jan 28 2009, 03:19 PM) <{POST_SNAPBACK}>
This is bothering me very much, i have absolutely no idea why it's not working so if someone could fix this i would appreciate it oh so very much!

I have a trigger:
^Disgustingly, (\\w+) spits at you, hitting you directly in your face\\.$

Alternatively, I've also found the same trigger line in Treant:

^Disgustingly\\, +\\ spits at you\\, hitting you directly in your face\\.$

I want to capture the person's name at (\\w+) and SetVariable('target', %0) but mushclient keeps giving me the error

string "Trigger: affnekospit__"]:1: ')' expected near 'spits'

And nothing i do seems to fix this. There's no open paranthesis i see anywhere that needs to be closed. I'm thinking maybe the regex might've captured ' spits' together which is why the unconcatenated string will cause a problem.

Any help at all is appreciated =]
Thanks!

EDIT: Oh and by the way, I'm working with Lua on MushClient.
EDIT: And i just realized there's a mushclient topic already. Should i move it there?


I'd use
^Disgustingly, (\\w+) spits at you, hitting you directly in your face\\.$
as your regex (making sure you have regex checked of course).

Your script should read
SetVariable("target","%1")

The reason is that %1 is not handled like a traditional variable, but rather as a literal. You must enclose it in quotes for it to be recognized as a string.

Yoruk2009-01-29 02:17:11
It worked!
Thanks so much!
I've always thought if i used %1 in quotes it would literally place "%1" in the target variable.


Unknown2009-01-29 03:18:52
I use + to capture people's names a little more carefully, as I don't ignore case on 99% of my triggers. It doesn't really matter either way. It's just me being paranoid or something.
Unknown2009-01-29 03:22:14
QUOTE (Zarquan @ Jan 29 2009, 11:18 AM) <{POST_SNAPBACK}>
I use + to capture people's names a little more carefully, as I don't ignore case on 99% of my triggers. It doesn't really matter either way. It's just me being paranoid or something.

With my rudimentary grasp of regular expression, wouldn't that mean that if for some reason, you were fighting someone whose name has only two alphabets, it would not trigger?
boshoku2009-01-29 04:18:52
QUOTE (Caerulo @ Jan 28 2009, 09:22 PM) <{POST_SNAPBACK}>
With my rudimentary grasp of regular expression, wouldn't that mean that if for some reason, you were fighting someone whose name has only two alphabets, it would not trigger?

With + are you matching something that's in sentence case? Are there people name things like rObeRto? or names like S'Karra or whateves?
Isuka2009-01-29 04:24:59
QUOTE (Caerulo @ Jan 28 2009, 07:22 PM) <{POST_SNAPBACK}>
With my rudimentary grasp of regular expression, wouldn't that mean that if for some reason, you were fighting someone whose name has only two alphabets, it would not trigger?


No. It would capture on a Capital letter followed by at least one and then any number of lower case letters.

Also, I'm fairly certain that characters must be at least four letters in length in Lusternia.
Unknown2009-01-29 04:30:41
QUOTE (Isuka @ Jan 29 2009, 12:24 PM) <{POST_SNAPBACK}>
No. It would capture on a Capital letter followed by at least one and then any number of lower case letters.

Also, I'm fairly certain that characters must be at least four letters in length in Lusternia.

Ok, so let me try to reason this. means that it has to start with a capital letter. means that it is followed by one small-case letter. + means that there must be 1 or more quantifiers after the small-case letter. Am I wrong somewhere?

Tau.
Isuka2009-01-29 05:06:44
QUOTE (Caerulo @ Jan 28 2009, 08:30 PM) <{POST_SNAPBACK}>
Ok, so let me try to reason this. means that it has to start with a capital letter. means that it is followed by one small-case letter. + means that there must be 1 or more quantifiers after the small-case letter. Am I wrong somewhere?

Tau.


Try reading it out loud like this:
"A single, capital character from A to Z, followed by at least one but possibly many lower cased letters from a to z."

But yes, you're right.
Unknown2009-01-29 05:47:47
So, basically, the + refers to ? Meaning, 1 or more letters? Instead of one small-case letter followed by at least one more letter/number/symbol?
Esano2009-01-29 05:56:25
The + expands on the , so it means 'one or more things that satisfy ', so 'one or more lower-case letters'.
Unknown2009-01-29 06:48:38
Ah, ok, thanks. So If I had ++, that would mean 1 or more capital letters followed by 1 or more smaller-case letters?
Esano2009-01-29 08:04:10
Yes.