Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to "verify" your details, 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.
Entire forum
➜ MUSHclient
➜ General
➜ question about capturing messages with regular expressions
question about capturing messages with regular expressions
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Gunner
Argentina (31 posts) Bio
|
Date
| Thu 23 Jul 2020 12:38 AM (UTC) |
Message
| Hi.
I would like to know how to capture a message until the point in which there are multiple spaces in a row, and if after those spaces, there is more text, capture it in another wildcard.
Thanks | Top |
|
Posted by
| Nick Gammon
Australia (23,070 posts) Bio
Forum Administrator |
Date
| Reply #1 on Thu 23 Jul 2020 03:26 AM (UTC) Amended on Thu 23 Jul 2020 03:29 AM (UTC) by Nick Gammon
|
Message
| This should do it:
To break that down:
- ^ --> Assert start of line
- (.+) --> match anything, capture it
- <space>{2,} --> match two or more spaces (note there is a space before the brace)
- (.*)? --> match anything, capture it (optional)
- $ --> Assert end of line
Example trigger:
<triggers>
<trigger
custom_colour="2"
enabled="y"
match="^(.+) {2,}(.*)?$"
regexp="y"
send_to="2"
sequence="100"
>
<send>
wildcard 1 is: %1
wildcard 2 is: %2
</send>
</trigger>
</triggers>
|
For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.
|
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Gunner
Argentina (31 posts) Bio
|
Date
| Reply #2 on Thu 23 Jul 2020 12:32 PM (UTC) Amended on Thu 23 Jul 2020 12:50 PM (UTC) by Fiendish
|
Message
| OK, but don't work :)
My trigger is:
Match: ^\s*(\d+)\)\s\[(\d+)\]\s\w+\s+(.+) {2,}(.+) {2,}$
the message to capture is:
"6) [65] Consigue el Martillo del Alma Infierno "
In the wildcard %3 the text is: "el martillo del alma infierno"
So I would like to capture "el martillo del alma" in the wildcard %3, and "infierno" in the wildcard %4 | Top |
|
Posted by
| Nick Gammon
Australia (23,070 posts) Bio
Forum Administrator |
Date
| Reply #3 on Thu 23 Jul 2020 09:25 PM (UTC) |
Message
| It might have saved a day if you had mentioned your exact data in your first post.
Your problem here is that you have two places with multiple spaces, and the regexp isn't sure which one to stop at.
It might be easier to just capture the first part of the line (which is easy) and then use scripting to pull out up to the first lot of multiple spaces
<triggers>
<trigger
custom_colour="2"
enabled="y"
match="^\s*(\d+)\)\s\[(\d+)\]\s(.*)$"
regexp="y"
send_to="12"
sequence="100"
>
<send>
print ("wildcard 1 is: %1")
print ("wildcard 2 is: %2")
print ("wildcard 3 is: %3")
first_part, second_part = string.match ("%3", "^(.-)%s%s+(.*)")
print ("first_part is", Trim (first_part))
print ("second_part is", Trim (second_part))
</send>
</trigger>
</triggers>
The Lua pattern looks for anything (non-greedy) followed by two or more spaces, and then anything else. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Fiendish
USA (2,533 posts) Bio
Global Moderator |
Date
| Reply #4 on Thu 23 Jul 2020 10:43 PM (UTC) Amended on Thu 23 Jul 2020 10:46 PM (UTC) by Fiendish
|
Message
| I don't think that's needed. Just make the ".+" nongreedy instead.
^\s*(\d+)\)\s\[(\d+)\]\s\w+\s+(.+?) {2,}(.+?) {2,}$
See https://regex101.com/r/f32tc7/1 |
https://github.com/fiendish/aardwolfclientpackage | 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.
13,821 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top