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 ➜ Lua ➜ Trying to capture odd arguements

Trying to capture odd arguements

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


Posted by Aidyn.Hartfire   USA  (15 posts)  Bio
Date Mon 14 Jul 2008 08:36 AM (UTC)

Amended on Mon 14 Jul 2008 09:06 AM (UTC) by Nick Gammon

Message
Alright, here is the problem, I'm trying to capture the below prompt--which has several asterisks, hyphens, spaces and newlines in it--for a trigger that would loop off of a timer to initiate the alias which sends this data to the output. I want it in regular expression. I tried everything I could think of for about 4 hours yesterday. Can anyone solve this problem for me or at least point me in the right direction?


Your wound status is:
*******************************************************************************
Body Part       Wounds     Wound Status    Ruptures   Rupture Status  
-------------------------------------------------------------------------------
Head            0          none            0
Chest           0          none            0
Gut             0          none            0
Right Arm       0          none            0
Left Arm        0          none            0
Right Leg       0          none            0
Left Leg        0          none            0
*******************************************************************************


I'm also doing this for the Chat Redirector plugin that Nick made. Everything else I have modified it for works, but this one has proven to be most tricky. At any rate, your help would be much appreciated. Thanks!


EDIT: It doesn't show it properly, but there are about 8-12 spaces between each of the body parts, the numbers, "none", and the last number. What I was trying was \s{1,} to capture any number of spaces. But, I think it was actually botching the hyphens. I could post the error message, if that helps anyone.

if me = "confused" then
SetVariable ("idiot", "yes")
Send ("choke")
DoAfter (3, "curse")
else Send ("fist pumpage")
end -- if
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #1 on Mon 14 Jul 2008 09:08 AM (UTC)
Message
Can you show what you tried? The stuff there looks straightforwards enough, I would have used a few triggers, one for each line type.

For example, to match the hyphens line, which looks like 79 hyphens to me, you could use:

^\-{79}$

- Nick Gammon

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

Posted by Aidyn.Hartfire   USA  (15 posts)  Bio
Date Reply #2 on Mon 14 Jul 2008 02:16 PM (UTC)
Message
Here is the first one I saved that I was trying. A bit clunky and amateur, but I only do this in my free time. You can still laugh though.


^Your wound status is\:^\*{1,}^(Body Part)\s{1,}(Wounds)\s{1,}(Wound Status)\s{1,}(Ruptures)\s{1,}(Rupture Status)\s{1,}^(\D{1,})^(Head)\s{1,}(*)\s{1,}(none|light|negligible|medium|heavy|critical)\s{1,}(*)^(Chest)\s{1,}(*)\s{1,}(none|light|negligible|medium|heavy|critical)\s{1,}(*)^(Gut)\s{1,}(*)\s{1,}(none|light|negligible|medium|heavy|critical)\s{1,}(*)^(Right Arm)\s{1,}(*)\s{1,}(none|light|negligible|medium|heavy|critical)\s{1,}(*)^(Left Arm)\s{1,}(*)\s{1,}(none|light|negligible|medium|heavy|critical)\s{1,}(*)^(Right Leg)\s{1,}(*)\s{1,}(none|light|negligible|medium|heavy|critical)\s{1,}(*)^(Left Leg)\s{1,}(*)\s{1,}(none|light|negligible|medium|heavy|critical)\s{1,}(*)^\*{1,}$


Looking back, I think I see one of the problems. There are no endline statements to match the newline statements. That is, no $ to match the ^ except for the last one. Heh. Like I said, amateur.


But I am trying your suggestion now to see if it'll work. I should do the same for the others (spaces, asterisks, etc) correct? Except with the right prefix.

if me = "confused" then
SetVariable ("idiot", "yes")
Send ("choke")
DoAfter (3, "curse")
else Send ("fist pumpage")
end -- if
Top

Posted by Aidyn.Hartfire   USA  (15 posts)  Bio
Date Reply #3 on Mon 14 Jul 2008 02:49 PM (UTC)

Amended on Mon 14 Jul 2008 07:26 PM (UTC) by Aidyn.Hartfire

Message
Alright, I did some editing and I will post that below. However, here is the returned error message I get:


Line 46: Error "Failed: nothing to repeat at offset 126" processing regular expression "^Your wound status is\:$^\*{79}^Body Part\s{7}Wounds\s{5}Wound Status\s{4}Ruptures\s{3}Rupture Status\s{3}$^\-{79}$^Head\s{12}*\s{10}(none|light|negligible|medium|heavy|critical)\s{12}*$^Chest\s{11}*\s{10}(none|light|negligible|medium|heavy|critical)\s{12}*$^Gut\s{13}*\s{10}(none|light|negligible|medium|heavy|critical)\s{12}*$^Right Arm\s{7}*\s{10}(none|light|negligible|medium|heavy|critical)\s{12}*$^Left Arm\s{8}*\s{10}(none|light|negligible|medium|heavy|critical)\s{12}*$^Right Leg\s{7}*\s{10}(none|light|negligible|medium|heavy|critical)\s{12}*$^Left Leg\s{8}*\s{10}(none|light|negligible|medium|heavy|critical)\s{12}*$^\*{79}$" (trigger not loaded)



Included in there is the entire trigger message. Should I just do a trigger for each newline instead of trying to clump it all together then?


EDIT: Alright, I edited it through and separated each one. When I reinstalled the same error came up for each trigger. After counting through the offset, it appears that the space is what is throwing it off. Should I just get rid of them altogether, repeat \s the amount of times there are spaces, or is that not the right way to indicate a space?


FINAL EDIT: This will, as the title implies, serve as my final update for this topic. I seem to have cracked the code on this one as it is working perfectly fine. At this moment. Anyhow, apparently using the \s isn't very useful. In fact, it will return the error that I displayed above. What did wind up working was creating a new trigger for each newline (as per Nick's suggestion). For those that contained spaces I just cut & pasted without trying to indicate that there were spaces there. It works without a hitch. For those lines that contained hyphens or asterisks using the \*{79} and \-{79} works flawlessly. However, I was forgetting that it isn't necessary to have those displayed on the screen as they are, so you don't have to include those in the triggers. But, as the other triggers will send the other prompts to a new window you will have orphaned asterisks and hyphens. I decided to transfer to whole prompt over for aesthetics over simplicity. Your choice really. I will probably be posting this over on the Plugins section for my fellow Lusternia users who are interested in learning how to do this, or just want to cut the work out and get it right off the bat. Anyhow, sorry to have bothered anyone. Take care!

if me = "confused" then
SetVariable ("idiot", "yes")
Send ("choke")
DoAfter (3, "curse")
else Send ("fist pumpage")
end -- if
Top

Posted by Worstje   Netherlands  (899 posts)  Bio
Date Reply #4 on Mon 14 Jul 2008 06:51 PM (UTC)
Message
You have things like: Gut\s{13}* at multiple places in your trigger. The \s{13}* part is invalid. You are literally saying 'a space repeated 13 times repeated 0 to infinity amount of times'. The * equals {0,}. So what it whines about is that there is nothing for the * to repeat. After all, you already specified the repetition for the \s part.

I can't be bothered reading through your entire regex and previous posts, but you would either need to make is \s{13} for 13 spaces, or \s* for an undefined amount of spaces (incl 0).

If you just want to match the asterisk * character, you should use \*.
Top

Posted by Aidyn.Hartfire   USA  (15 posts)  Bio
Date Reply #5 on Mon 14 Jul 2008 07:36 PM (UTC)
Message
I already got it worked out, but the asterisks without the prefix were originally supposed to indicate any value, starting with 0 to infinite. If you look at the initial post, and cross-reference it to the RegExp, you would notice the correlation. However, I fixed it altogether by just using spaces in the triggers and denoted the 0-infinite by (.*?). It works as it is currently. I might go back later to try and enhance the code to read faster once I know quite a bit more about doing so. Anyhow, thanks for the input. It is something I can at least apply on future projects.

if me = "confused" then
SetVariable ("idiot", "yes")
Send ("choke")
DoAfter (3, "curse")
else Send ("fist pumpage")
end -- if
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #6 on Tue 15 Jul 2008 02:43 AM (UTC)
Message
Just to clarify here, Worstje is correct.

In a non regular expression an asterisk means "zero or more of any character", as in:


You see a * here


However in a regular expression an asterisk simply means "zero or more of the preceding character or group".

It is important that you realize that.

For example the regular expression:


You see a * here


... will compile OK, but what it is doing is matching one or more spaces between "a" and "here". The first part is (space)* which means zero or more spaces, followed by the other space.

To replicate the original, you need to add "." which is "any character", thus:


You see a .* here


To be more faithful to the non-regular expression version you need to make it a group (so it is returned as a capture):


You see a (.*) here


And to be completely faithful you need to make it a non-greedy match, with the extra ?, like this:


You see a (.*?) here


If you do something like you had:


a{,79}*


It doesn't make sense. You are asking for 'zero or more' of 'zero to 79' of 'a'.




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


21,031 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.