[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Regular Expression help

Regular Expression help

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


Posted by Strazor   USA  (24 posts)  [Biography] bio
Date Tue 26 Aug 2014 05:44 PM (UTC)

Amended on Tue 26 Aug 2014 05:46 PM (UTC) by Strazor

Message
I'm brand new to regular expressions. I've read http://www.gammon.com.au/mushclient/regexp.htm and I'm having trouble visualizing what I need. How can I ignore the white space and simplify this to not worry about spacing?


    <trigger
        enabled="y"
        match="^\| Type       \: (.*?)                  Level  \:     (.*?)           \|$"
        regexp="y"
        script="capture_type_level"
    >
    </trigger>


I am extracting the data from the "ID pearl" command on aardwolf. Here is an example.


+-----------------------------------------------------------------+
| Keywords   : 41neck openstock touchstone pearl Asura            |
| Name       : (>Asura's Azurite Pearl<)                          |
| Id         : 965751006                                          |
| Worn       : Neck                                               |
| Type       : Armor                     Level  :    41           |
| Worth      : 5,060                     Weight :     0           |
| Wearable   : neck                                               |
| Score      : 185                                                |
| Material   : pearl                                              |
| Flags      : unique, glow, hum, magic, held, burn-proof,        |
|            : solidified, illuminated, V3                        |
| Notes      : This item is from a clan hall.                     |
| Notes      : Item has 2 resistance affects.                     |
+-----------------------------------------------------------------+
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Tue 26 Aug 2014 07:37 PM (UTC)
Message
Use \s+ to match one or more spaces.


<triggers>
  <trigger
   enabled="y"
   match="^\| Type\s+\: (\w+)\s+Level\s+\:\s+(\d+)\s+\|$"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>

Note ("Type = %1")
Note ("Level = %2")

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


Template:pasting For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.


Also if you know you are expecting digits you can use \d+ (one ore more digits). The above worked on your test data.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Strazor   USA  (24 posts)  [Biography] bio
Date Reply #2 on Tue 26 Aug 2014 08:35 PM (UTC)
Message
Thank you Nick. Very helpful.
[Go to top] 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.


10,507 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]