Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
Haldrik
Wanderer


Joined: 03 Sep 2007
Posts: 88

PostPosted: Thu Nov 20, 2008 6:59 pm   

RegExpression Help
 
I've been reading that reg expression tutorial and so far its been crazy helpful. I'm about about 1/3 through right now though. Anyways, I've been trying to make an expression and could some some help.


Pattern:
Swimming: 15 19% concentrating Scholarship: 55 00% thoughtful
OR
Swimming: 15 19% concentrating
or
Scholarship: 55 00% thoughtful Swimming: 15 19% concentrating

Code:
Swimming:%s%d %d~% [^(mind lock)]



I've been trying to get both mind lock AND the negation of mind lock. Basically 2 seperate triggers, 1 that triggers on mind lock, and one that triggers off everything else.


Basically the negation works really well, except strangely its negating everything with an M, which makes sense... because of the character by character regex engine. But i though the () would group together the word...

Anyways, I'm pretty sure this is super easy and I'm missing somethign really simple.



Any help would be greatly appreciated!

Thanks :)
Reply with quote
Haldrik
Wanderer


Joined: 03 Sep 2007
Posts: 88

PostPosted: Thu Nov 20, 2008 7:05 pm   
 
So I think I figured out a zscript way...

Code:
Swimming:%s%d %d~% %w{^mind lock}



But I would be interested in learning how regex does it?



Edit: doesnt work after all.
Reply with quote
cazador
Apprentice


Joined: 08 Dec 2005
Posts: 108

PostPosted: Thu Nov 20, 2008 7:50 pm   
 
Swimming: 15 19% concentrating Scholarship: 55 00% thoughtful
OR
Swimming: 15 19% concentrating
or
Scholarship: 55 00% thoughtful Swimming: 15 19% concentrating

You could do
Code:

^(?:Scholarship|Swimming): \d{2} \d{2}% (?:concentrating|thoughtful)
or
^\S+ \d{2} \d{2}% (?:concentrating|thoughtful)

Or simplist Swimming:


Edit: To read up more about reg ex. CMUD regex uses perl regex, so you can do a google on "perl regex" and get some nice websites with the regex documentation
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Thu Nov 20, 2008 7:55 pm   
 
Personally, I'm not sure exactly what you're trying to match. You gave us three examples, but then you talk about "mind lock" which isn't even listed anywhere in your examples. You'll need to be more elaborate in what you're trying to do.

As an aside, you could use:

(?:mind lock)? -> which will match mind lock if it's there, otherwise it'll ignore it. Just a thought. Provide better examples for better instructions.

Charneus
Reply with quote
Haldrik
Wanderer


Joined: 03 Sep 2007
Posts: 88

PostPosted: Thu Nov 20, 2008 8:36 pm   
 
Ah,

I specifically said I needed something that triggered off the negation of mind lock(hence no mind lock in the examples). I am sorry I wasn't clear enough.

Quote:
I've been trying to get both mind lock AND the negation of mind lock. Basically 2 seperate triggers, 1 that triggers on mind lock, and one that triggers off everything else.


The examples I gave were just for positioning purposes in case ya needed to know white spaces etc. But there was an example of mind lock in the code section too.

There is about 10 lines of "mind states", anywhere from clear to the last which is mind lock. Instead of listing each individual mind state..

i.e. (?:concentrating|thoughtful|muddled) etc etc etc.

Pattern:
Swimming: 15 19% mind lock (here is your example)

I want the NEGATION of mind lock. I think this way will be a lot more efficient then listing all 10 other choices.


But to he honest, the Negation of Mind should be good enough.

Are we talking something like this (^?:mind lock)?

I'll have to play around a bit more...



And Cazador, I plugged in your examples too. Neither of the regex expressions worked. (I have regEx checked)



Thanks guys.
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Thu Nov 20, 2008 8:43 pm   
 
So if mind lock is there, you want to ignore it, but if it's NOT there, you want the trigger to fire?

Charneus
Reply with quote
Haldrik
Wanderer


Joined: 03 Sep 2007
Posts: 88

PostPosted: Thu Nov 20, 2008 8:47 pm   
 
Nah, I need two triggers.


Trigger on mindlock will do a certain action.


But if its NOT mindlock, so it would be the 9 other stages(i.e. thoughtful/concentrationg) It will do something else.


That help?


Thanks charneus.
Reply with quote
Haldrik
Wanderer


Joined: 03 Sep 2007
Posts: 88

PostPosted: Thu Nov 20, 2008 8:50 pm   
 
So... I came up with this


Code:
Swimming:\s+\d+ \d+\% (?:(?!mind lock)(?<!mind lock))



What do you think?
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5187

PostPosted: Thu Nov 20, 2008 8:58 pm   
 
Why use two triggers when you can use an optional portion of the pattern and test it in the script?
Code:
#REGEX {(?:Scholarship|Swimming):\s+\d{2} \d{2}% (mindlock)?} {#IF (%1="") {
 #SHOW not mindlocked
} {
 #SHOW mindlocked
}}
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Haldrik
Wanderer


Joined: 03 Sep 2007
Posts: 88

PostPosted: Thu Nov 20, 2008 9:06 pm   
 
Oooo. What a great idea Vijilante. Is that also a lot more efficient?

I just tested it out, its working great. Care to explain a bit about how the %1 part works? Which part of the regex is the %1 coming from?



Thanks a ton :) I always want to be more efficient. I started reading regex stuff so i could learn more about "greedy". Lol.
Reply with quote
cazador
Apprentice


Joined: 08 Dec 2005
Posts: 108

PostPosted: Thu Nov 20, 2008 9:11 pm   
 
What you could do is trigger at
Code:

^(?:Swimming|Scholarship): \d+ \d+% ($val:\s+)


the \d+ will let you catch on 1 or more digits,
the ($val:\s+) will store a string into the local variable $val
And in the trigger you can do an something like:
pseudo-code below
Code:

if ($val = 'mindlock')
{ do stuff
}
else
{ do other stuff }


Then you would only need one trigger and you would have smarts in what the trigger does
Reply with quote
cazador
Apprentice


Joined: 08 Dec 2005
Posts: 108

PostPosted: Thu Nov 20, 2008 9:13 pm   
 
i typed to slow . .and didn't get my answer done in time .. oh well
the %1 gets captured to anything in the first (), the %2 gets captured in the second (), etc ... note (?:) does not get captured.

If you want to use named variables you can do ($var:pattern)
Reply with quote
Haldrik
Wanderer


Joined: 03 Sep 2007
Posts: 88

PostPosted: Fri Nov 21, 2008 1:28 am   
 
Nice, thanks guys.

A lot of options and I learned a ton.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net