Gammon Forum
Entire forum
MUSHclient
Tips and tricks
Reg exp trouble!
It is now over 60 days since the last post. This thread is closed.
  Refresh page
Posted by
| Cyb Ercho Lin
Argentina (10 posts) bio
|
Date
| Sat 18 Mar 2017 04:51 AM (UTC) Amended on Sat 18 Mar 2017 09:06 PM (UTC) by Nick Gammon
|
Message
| I am having problems to be able to do a trigger that orders me by categories an information that throws a command to me.
This is an example of what appears in a single line:
Level of knowledge 90% Level of domain High Chakra 200
Healing ability Gifted Reach 5
Inheritance 50
In this example, the first line has 3 components, the second line 2 components and the third 1 component. The order of the 3 lines is random.
I would like to use a trigger to sort these lines.
for example:
Line 1:
Level of knowledge 90%
Level of domain High
chakra 200
Line 2:
Healing ability Gifted
reach 5
Line 3:
Inheritance 50
I've tried to fix it with this:
Reg Exp:
[\s](.+?)[\s](\d+)\%[\s](.+)[\s](\d+)[ ](\d+)[\s](.+)[\s](\d+)[\s]
With this line only shows me the data of the first line that contains 3 parts, but if there are only 2 parts does not show anything and if it is only 1 part also does not show the data.
Any idea how to fix it? | top |
|
Posted by
| Nick Gammon
Australia (22,975 posts) bio
Forum Administrator |
Date
| Reply #1 on Sat 18 Mar 2017 09:08 PM (UTC) |
Message
| Can you please post the actual trigger?
|
For advice on how to copy aliases, timers or triggers from within MUSHclient, and paste them into a forum message, please see Copying XML.
|
I'm a bit confused about your regexp. A "set" is something in brackets, like [abc] which would match "a" or "b" or "c".
When you have this:
That is only going to match a space, so the brackets aren't required. Plus it only matches one space, and in your example you have multiple spaces. To match one or more spaces you want:
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|
Posted by
| Cyb Ercho Lin
Argentina (10 posts) bio
|
Date
| Reply #2 on Sat 18 Mar 2017 10:20 PM (UTC) Amended on Sun 19 Mar 2017 06:38 AM (UTC) by Nick Gammon
|
Message
| I made some changes after reading your suggestion in the change to \s+
The actual code:
<trigger
enabled="y"
expand_variables="y"
group="Books"
keep_evaluating="y"
match="\s+(.*)\s+(\d+)\%\s+(.*)\s+(\d+)\%\s+(.*)\s+(\d+)\%\s+$"
omit_from_log="y"
omit_from_output="y"
regexp="y"
send_to="2"
sequence="100"
>
<send>%1 %2
%3 %2
%5 %6
</send>
</trigger>
Works fine when there are 3 elements in the line as in line 1 of the example. If it is the second line or the third, it does not work.
Use the following line to format the text.
As I said before, it works perfectly if there are 3 elements in the line, but if there are only 2 or 1 element does not work.
ColourNote ("white", "", string.format ("%%-25s %i%s", Trim ("%1"), %2,"%"))
The result:
Level of knowledge 90%
Level of domain High
chakra 200
with 2 elements:
Healing ability Gifted Reach 5
| top |
|
Posted by
| Nick Gammon
Australia (22,975 posts) bio
Forum Administrator |
Date
| Reply #3 on Sun 19 Mar 2017 06:42 AM (UTC) |
Message
| You can make part of the regexp optional. eg.
^(part one)(\s+part two)?(\s+part three)?$
This has to match "part one" but also matches "part one part two" and also "part one part two part three".
|
Regular expressions
- Regular expressions (as used in triggers and aliases) are documented on the Regular expression tips forum page.
- Also see how Lua string matching patterns work, as documented on the Lua string.find page.
|
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|
Posted by
| Cyb Ercho Lin
Argentina (10 posts) bio
|
Date
| Reply #4 on Sun 19 Mar 2017 07:28 AM (UTC) |
Message
|
Nick Gammon said:
You can make part of the regexp optional. eg.
^(part one)(\s+part two)?(\s+part three)?$
This has to match "part one" but also matches "part one part two" and also "part one part two part three".
Part 1: \s+(.*)\s+(\d+)\%
Part 2: \s+(.*)\s+(\d+)\%
Part 3: \s+(.*)\s+(\d+)\%\s+$
^((.*)\s+(\d+)\%)(\s+(.*)\s+(\d+)\%)?(\s+(.*)\s+(\d+)\%)?\s+$
But with this regexp not working | top |
|
Posted by
| Nick Gammon
Australia (22,975 posts) bio
Forum Administrator |
Date
| Reply #5 on Sun 19 Mar 2017 09:30 AM (UTC) |
Message
|
Part 2: \s+(.*)\s+(\d+)\%
"Level of domain High" doesn't have a % symbol in it. |
- 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.
18,652 views.
It is now over 60 days since the last post. This thread is closed.
  Refresh page
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.