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 ➜ Regex failing to capture one part in wildcards

Regex failing to capture one part in wildcards

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


Posted by Rabbi   (5 posts)  Bio
Date Fri 11 Oct 2019 02:28 PM (UTC)

Amended on Sat 12 Oct 2019 12:40 PM (UTC) by Rabbi

Message
The text to match looks like one of these:
<938/941Hp 251/251mn 583/586mv> [0|Witch Wood] (a goblin)

<938/941Hp 251/251mn 583/586mv> [0|Witch Wood] ()


This is the regex that I'm using:
\<(\d+)\/(\d+)Hp (\d+)\/(\d+)mn (\d+)\/(\d+)mv\> [\d\|.+] \((.*)\)


Matches 1-6 are fine, wildcard 7 should be "a goblin" some of the time.
function ProcessPrompt(name, text, wildcards)
    SetVariable("currentHealth", tonumber(wildcards[1]))
    SetVariable("maxHealth", tonumber(wildcards[2]))
    SetVariable("currentMana", tonumber(wildcards[3]))
    SetVariable("maxMana", tonumber(wildcards[4]))
    SetVariable("currentMovement", tonumber(wildcards[5]))
    SetVariable("maxMovement", tonumber(wildcards[6]))
    SetVariable("target", wildcards[7])
    Tell(wildcards[7])
    SetVariable("waitingForPrompt", "false")
end

I never see the output from that "Tell", but it works and sets the variables correctly for the other wildcards.
Top

Posted by Fiendish   USA  (2,535 posts)  Bio   Global Moderator
Date Reply #1 on Fri 11 Oct 2019 06:03 PM (UTC)

Amended on Fri 11 Oct 2019 06:22 PM (UTC) by Fiendish

Message
The pattern is busted and will not trigger on the given text. You want \[ and \] not [ and ]

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Nick Gammon   Australia  (23,140 posts)  Bio   Forum Administrator
Date Reply #2 on Fri 11 Oct 2019 08:36 PM (UTC)
Message
If you are posting to the forum you need to double the number of backslashes. See MUSHclient's Edit menu -> Convert clipboard forum codes. That will do it for you (to text you have on the clipboard).

- Nick Gammon

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

Posted by Rabbi   (5 posts)  Bio
Date Reply #3 on Fri 11 Oct 2019 08:44 PM (UTC)
Message
Nick Gammon said:

If you are posting to the forum you need to double the number of backslashes. See MUSHclient's Edit menu -> Convert clipboard forum codes. That will do it for you (to text you have on the clipboard).

Nice feature! I'll do that tonight, thank you.
Top

Posted by Nick Gammon   Australia  (23,140 posts)  Bio   Forum Administrator
Date Reply #4 on Fri 11 Oct 2019 08:47 PM (UTC)

Amended on Fri 11 Oct 2019 08:52 PM (UTC) by Nick Gammon

Message
I'm assuming you didn't do that, based on the look of the rest of your raw post, so this is your trigger:


<triggers>
  <trigger
   enabled="y"
   match="\&lt;(\d+)\/(\d+)Hp (\d+)\/(\d+)mn (\d+)\/(\d+)mv\&gt; \[\d\|.+\] \((.*)\)"
   regexp="y"
   script="ProcessPrompt"
   sequence="100"
  >
  </trigger>
</triggers>


With the extra forum backslashes (almost as annoying as the password requirements, eh?) you can see that the square brackets are indeed escaped.

I changed your script to read:



function ProcessPrompt(name, text, wildcards)
    print("currentHealth", tonumber(wildcards[1]))
    print("maxHealth", tonumber(wildcards[2]))
    print("currentMana", tonumber(wildcards[3]))
    print("maxMana", tonumber(wildcards[4]))
    print("currentMovement", tonumber(wildcards[5]))
    print("maxMovement", tonumber(wildcards[6]))
    print("target", wildcards[7])
    print(wildcards[7])
    print("waitingForPrompt", "false")
end



On your test data I can't reproduce your problem:



<938/941Hp 251/251mn 583/586mv> [0|Witch Wood] (a goblin)

currentHealth 938
maxHealth 941
currentMana 251
maxMana 251
currentMovement 583
maxMovement 586
target a goblin
a goblin
waitingForPrompt false

<938/941Hp 251/251mn 583/586mv> [0|Witch Wood] ()

currentHealth 938
maxHealth 941
currentMana 251
maxMana 251
currentMovement 583
maxMovement 586
target 

waitingForPrompt false



Added blank lines for clarity. You can see that "a goblin" is recognized. Note that Tell does not show a newline, so with Tell there rather than print you won't see anything until you display something else with a newline in it.

Template:version Please help us by advising the version of MUSHclient you are using. Use the Help menu -> About MUSHclient.

- 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,803 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.