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 Goto page 1, 2  Next
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Wed Mar 26, 2008 10:02 pm   

Some regex
 
Quote:

* tells you [*\(*\)] '*'$|^You tell [*] '*'$|* tells the group '*'$


This is supposed to capture any and all of the following:

You tell Andria 'No, not tonight.'

Andria tells you 'Yes, Friday will work instead.'

Andria tells you (Elvish) 'No, I cannot do Thursday'

You tell the group 'Left, go left'

Andria tells the group 'I can't go left'
Reply with quote
alluran
Adept


Joined: 14 Sep 2005
Posts: 223
Location: Sydney, Australia

PostPosted: Wed Mar 26, 2008 10:06 pm   
 
change your square brackets to round ones and it might work
_________________
The Drake Forestseer
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Wed Mar 26, 2008 10:09 pm   
 
And I would encase the entire thing in { }?
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
alluran
Adept


Joined: 14 Sep 2005
Posts: 223
Location: Sydney, Australia

PostPosted: Wed Mar 26, 2008 10:12 pm   
 
Code:
^(?:.* tells you (.*\(.*\)) '.*'|You tell (.*) '.*'|.* tells the group '.*')$


That should work, you got some wierd hybrid of zscript patterns and regexp in your code, i just saw
_________________
The Drake Forestseer
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Wed Mar 26, 2008 10:15 pm   
 
Is it possible to explain what you changed?
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Wed Mar 26, 2008 10:19 pm   
 
Hmm,


Liluye tells you (Elvish) 'Testing!'

and

Liluye tells you 'Testing!'

didn't work.
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
alluran
Adept


Joined: 14 Sep 2005
Posts: 223
Location: Sydney, Australia

PostPosted: Wed Mar 26, 2008 10:20 pm   
 
Code:
(?:Some|Stuff|Here)

Matches Some, Stuff or Here, but doesnt store it at all, if i wanted to access it with %1 etc, i'd use:
Code:
(Some|Stuff|Here)


Code:
.*

Matches anything, but doesnt store it at all, if i wanted to access it with %1 etc, i'd use:
Code:
(.*)


^ and $ in the first type of pattern doesn't seem to work, which is why i moved it to the start and end of the pattern

I think that explains every pattern i used in that regexp?
_________________
The Drake Forestseer
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Wed Mar 26, 2008 10:22 pm   
 
Possibly, but none of them work. :/
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
alluran
Adept


Joined: 14 Sep 2005
Posts: 223
Location: Sydney, Australia

PostPosted: Wed Mar 26, 2008 10:27 pm   
 
you need to make sure the trigger is set to regexp, not normal trigger, the normal trigger would be vastly different

Code:
^{* tells you (*~(*~)) '*'|You tell (*) '*'|* tells the group '*'}$


or something
_________________
The Drake Forestseer
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Wed Mar 26, 2008 10:32 pm   
 
How do I set it to regexp?
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Wed Mar 26, 2008 10:35 pm   
 
I set it, nevermind.
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Wed Mar 26, 2008 10:42 pm   
 
I'm not sure what you want to do with the text once you have matched it. If you really did mean that you wanted to capture the text then you probably want to save it into %1.
For that you would use this pattern. [On the bottom right of the editor window under the trigger priority box you would check the Regular Expression box to make a trigger a regex trigger.]
Code:
^(.* tells you.* '.*'|You tell .* '.*'|.* tells the group '.*')$

If you simply want to match the text without placing it into %1 then the following pattern would work.
Code:
^(?:.* tells you.* '.*'|You tell .* '.*'|.* tells the group '.*')$

If you wanted to capture who sent the tell or what language you would need something a little different. But it did not look like that was what you were doing.

For sending text to another window you would need to use something like #CAP.
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Wed Mar 26, 2008 10:44 pm   
 
alluran wrote:
Code:
^(?:.* tells you (.*\(.*\)) '.*'|You tell (.*) '.*'|.* tells the group '.*')$



So...

^(?:.* = Anything before "tells you"

(.*\(.*\)) = Anything after "tells you" and before '*', including something in ()

'.*' = anything in ' '

etc... ?

Also of note. They talked about \r, carriage returns.

Can I use these in CMUD to match expressions along lines?

For instance, in DSL, we can get quests. Quests usually span multiple lines, but since I can see what everyone else gets, I think it would be neat if I could have the pattern match the whole set of strings (multiple lines) starting with the one with my name, so that no string that doesn't have my name would be matched.
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Wed Mar 26, 2008 10:50 pm   
 
Well, you would probably need to use \n instead of \r to match your line breaks/carriage returns for starters.
Next you need to actually know where the line breaks are... It can all get very messy.

If you use multi state triggers it is easier. I usually turn on or off several triggers based on a pattern instead of trying to match all possible combinations of line breaks.

#T+ triggerName

Turns on a trigger.

#T- triggerName

Turns off a trigger
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Wed Mar 26, 2008 10:53 pm   
 
I'll give you an example and we'll see what you think. I know where every line will end, yes.
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Wed Mar 26, 2008 10:54 pm   
 
(?:) means match what is in here but throw away the result. () means match what is in here and save the result to the next open %n. %n being %1 %2 %3 etc.

| is the OR character so this|that means to match this or that.
. matches any single character.
.* means match any combination of characters including none but excluding new lines or carriage returns.
.+ means the same as above except it does NOT include none + means one or more * means any amount.
\ is the escape character.
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Wed Mar 26, 2008 11:41 pm   
 
So here's an example of a DSL quest:

Quote:

You ask the ancient elven questmaster for a quest.
The ancient elven questmaster says 'Thank you, brave Yasan!'
You have asked to find a lost item.
The ancient elven questmaster says 'Vile pilferers have stolen the King's sceptre from the royal treasury!'
The ancient elven questmaster says 'My court wizardess, with her magic mirror, has pinpointed its location.'
The ancient elven questmaster says 'Look in the general area of Dividing Tunnels for Dwarven Barracks!'
The ancient elven questmaster says 'You have 21 hours to complete this quest.'
The ancient elven questmaster says 'May the gods go with you!'


If you see the end of each line is very clearly defined by the single quote marks. So I think one giant regex statement can be done. The question is, should it be done, or should multiple triggers be implemented? I'm assuming triggers can turn one another on and off?
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Thu Mar 27, 2008 8:29 am   
 
Okay, you're making this a million times more difficult than it needs to be :P There are far too many .*s in that pattern, which'll slow it down immensely. Here's something for you:

(tells you(?: \(\w+\))?|You tell \w+|You tell the group) '

This matches all those tell lines and should do so quite quickly. Depending on what you want you want to do, it might not have enough captures - if you give us the details of the script, we can suggest a better pattern. If you want to do something with the name and text, you could try this instead:

^(?:(\w+) tells you(?: \(\w+\))?|You tell \w+|You tell the group) '(.+)'

Triggers can turn one another off if the trigger has an ID (there's a field for it in the package editor). You then use the ID with #t+ and #t-.

However, capturing all that text is pretty easy.

#regex {You ask (.+?) for a quest} {QuestGiver=%1#t+ QuestCap}
#cond {You have (%d) hours to complete this quest} {#t- QuestCap}

#trig "QuestCap" {^@QuestGiver says '(*)'} {} "" {disable}

This uses a multistate trigger.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Thu Mar 27, 2008 8:54 am   
 
The tells one I have right now works. I'll be looking into multi state triggers, thanks.
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Thu Mar 27, 2008 4:15 pm   
 
The fastest way to match something in between quotes or brackets is a negated character class.

Code:
\w+ tells you \([^)]+\) '[^']+'


That will match anything between ( and ) and between ' and ' without backtracking. So someone could tell you in Elvish Northern dialect or whatever and it still matches. If it is just always a single word for the language, just use \w+. If you use a greedy or even a lazy dot star or plus you make that trigger go from taking 19 steps with no backtracking for the one I show above, up to hundreds of steps due to all the backtracking. Considering what they tell you can vary in length as well.

For example, the example Arminas gave above:

Code:
^(?:.* tells you.* '.*'|You tell .* '.*'|.* tells the group '.*')$


Took 178 steps to match the pattern...Andria tells you (Elvish) 'No, I cannot do Thursday'. Using the negated character class with a greedy + takes only 19 steps! It doesn't have to do any backtracking. You can use the negated character class in a lot more situations as well.
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Thu Mar 27, 2008 4:18 pm   
 
Ah, alright. Well, I'd change it, but I sort of want to find out why I have to create them every session for them to work. They don't disappear, they're still there. But they won't work unless I recreate them.
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Thu Mar 27, 2008 4:28 pm   
 
Your comments about negated character classes are true, but only when the tell can never contain the quotes that surround it. Since that's rarely true (especially given that the quotes in this case are apostrophes, which people use in tells all the time), your regex will miss bits off of many tells. \w+ is fine for the language name, but you need to use the dot for the tell because the tells can contain any character. It should only backtrack one step to match the apostrophe at the end, so that's not a problem. By the time it reaches the dot, the match isn't going to fail.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Thu Mar 27, 2008 4:42 pm   
 
What do you mean they don't work? Are they grayed out and disabled? You have to make sure the Regular Expression option for the trigger is checked.
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Thu Mar 27, 2008 5:01 pm   
 
They work, then I disconnect. I come back, connect to mud, disconnect and reconnect to avoid the stupid Read-Only bug and a select few of my triggers won't fire. Nothing has changed, they aren't disabled or anything. They just wont fire.
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Thu Mar 27, 2008 8:52 pm   
 
Oops Fang is right. More than likely someone will use an apostrophe or quotation mark within the quote so use .+.

As far as the read only thing and triggers not working, I'm not really sure what you are talking about.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
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