Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ General ➜ How do I capture part of a word?

How do I capture part of a word?

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Karl_Newbie   USA  (23 posts)  Bio
Date Sat 31 Jul 2004 08:02 PM (UTC)

Amended on Sat 31 Jul 2004 10:17 PM (UTC) by Karl_Newbie

Message
note: I figured out an alternative to solution.

This should be an easy one. On the line I see something like this.

Bernshire (5h2g3i23) men: 120 req: 1200 current: 0 (garrison)


My trigger below is intended to match that line and evaluate if the 'req: *' is greater than the 'current: *'.

If the 'req # is higher, it sends a command to the mud using some of the other parts of that line.
The command seems to send fine.
The problem is with the '(5h2g3i23)' The command being sent to the mud can only use what's inside the parenthesis, but my trigger matches all of it, including the parenthesis.


I tried using escape chars as the alternative trigger below, but then the line does not match at all.


"(@aland) \((.*?)\) men: (.*) req: (.*?) current: (.*?) (.*?)"


Okay edit: I got the trigger to work well on my own. Without regular expressions. I'm still not sure why the regular expressions didn't work.
"@aland (*) * men: * req: * current: * *"





match="(@aland) \((.*?)\) men: (.*) req: (.*?) current: (.*?) (.*?)"
Below is what I have.
The problem is it sends
'resupply (5h2g3i23) 1200'

When I just want 'resupply 5h2g3i23 12000 (those spaces don't seem to bother the mud)

-------------------------------------------------------
<triggers>
<trigger
custom_colour="2"
enabled="y"
expand_variables="y"
group="payland"
ignore_case="y"
match="(@aland) (.*?) men: (.*?) req: (.*?) current: (.*?) (.*?)"
regexp="y"
repeat="y"
send_to="12"
>
<send>if %4 &gt; %5 then
Send &quot;resupply %2 %4&quot;
world.note &quot;supplying now debug W1= %1 W2= %2 W3= %3 W4= %4 W5 = %5 W6= %6 W7= %7&quot;
else
world.note &quot;all required supplies are present Debug W1= %1 W2= %2 W3= %3 W4= %4 W5 = %5 W6= %6 W7= %7&quot;
end if

</send>
</trigger>
</triggers>
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #1 on Sat 31 Jul 2004 11:30 PM (UTC)

Amended on Sat 31 Jul 2004 11:33 PM (UTC) by Nick Gammon

Message
Quote:

Bernshire (5h2g3i23) men: 120 req: 1200 current: 0 (garrison)

...

I tried using escape chars as the alternative trigger below, but then the line does not match at all.


"(@aland) \((.*?)\) men: (.*) req: (.*?) current: (.*?) (.*?)"


You didn't escape enough, there are two lots of brackets in the line you are trying to match. Also, I wouldn't bother putting the name (@aland) in brackets, you don't need that back, after all it is already in a variable. Try this:


@aland \((.*?)\) men: (.*) req: (.*?) current: (.*?) \((.*?)\)


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #2 on Sat 31 Jul 2004 11:35 PM (UTC)
Message
If you are going to use regular expressions you may as well do it properly. For one thing, you are matching numbers so use \d instead of . (which matches any letters) and use + instead of *. + matches one or more, whereas * matches zero or more. Zero numbers won't be valid (by zero numbers I mean no numbers, not the number zero). Thus it might look like this:


@aland \((.*)\) men: (\d+) req: (\d+) current: (\d+) \((.*)\)


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #3 on Sat 31 Jul 2004 11:40 PM (UTC)

Amended on Sat 31 Jul 2004 11:42 PM (UTC) by Nick Gammon

Message
Then if you want to get fancy, use named wildcards, like this:


@aland \((?P<who>.*)\) men: (?P<men>\d+) req: (?P<req>\d+) current: (?P<current>\d+) \(?P<garrison>(.*)\)


Then you can test using names in the send text, like this:


if %<req> > %<current> then
  send "resupply %<who> %<req>"
end if


That makes it easier to read, without having to count which wildcard is which.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


12,030 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.