Regular Expression help

Posted by Strazor on Tue 26 Aug 2014 05:44 PM — 3 posts, 15,755 views.

USA #0
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.                     |
+-----------------------------------------------------------------+
Amended on Tue 26 Aug 2014 05:46 PM by Strazor
Australia Forum Administrator #1
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.
USA #2
Thank you Nick. Very helpful.