|
Dyron Apprentice
Joined: 08 Apr 2004 Posts: 103 Location: USA
|
Posted: Thu Apr 07, 2011 6:48 pm
Regex question I believe |
4078h, 3528m, 4156e, 10p, 17873en, 14460w, 1mo elrx-
4078h, 3528m, 4156e, 10p, 17880en, 14460w elrx-
I need to make a trigger that will read this prompt either way.. With or without the "1mo"
If the "1mo" is there.. I also want it to track the number.. the number can be between 1-5.. So basically
4078h, 3528m, 4156e, 10p, 17873en, 14460w, 1mo elrx-
4078h, 3528m, 4156e, 10p, 17873en, 14460w, 2mo elrx-
4078h, 3528m, 4156e, 10p, 17873en, 14460w, 3mo elrx-
or
4078h, 3528m, 4156e, 10p, 17880en, 14460w elrx-
Thanks in advance folks! |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Thu Apr 07, 2011 7:53 pm |
It would help if you could tell us which parts of that prompt you want to capture. Also, does it always end with "elrx-", or does it sometimes end with something else? Does this prompt end with a carriage return, or does it wait there for you to type something or for more text from the mud?
|
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Thu Apr 07, 2011 11:57 pm |
Nope, don't need regex. 9.9 times out of 10, regex is completely unnecessary on the grounds that there's simply no advantage nor disadvantage to using it.
#trigger {%dh...bunch of unimportant stuff you probably already have figured out...({ | %a }) elrx-} {
// have to do the matching this way because if %match() doesn't match the specified pattern it just fills the variable with something random
$mo = 0
#if (%1 != " ") {
#call %match(%1," (%d)mo ",$mo)
}
} |
|
_________________ EDIT: I didn't like my old signature |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4692 Location: Pensacola, FL, USA
|
Posted: Fri Apr 08, 2011 3:52 pm |
#TR {(%d)h, (%d)m, (%d)e, (%d)p, (%d)en, (%d)w{, (%d)mo|} elrx-} {#IF (%7) {#SAY %7}}
|
|
_________________ Discord: Shalimarwildcat |
|
|
|
chamenas Wizard
Joined: 26 Mar 2008 Posts: 1547
|
Posted: Sat Apr 09, 2011 2:02 am |
Shalimar's should work, but in regex the optional operator is ? after a block of pattern in parentheses.:
Code: |
\d+h, \d+m, \d+e, \d+p, \d+en, \d+w,(?: (\d+)mo)? elrx-
|
if %1 equals %null, then it didn't match, if it has a value, then it did. The neat thing about Shalimar's example is it simply won't fire when it doesn't need to, which is a bit more efficient. |
|
|
|
|
|
|
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
|
|