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.
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.
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!
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 \*.
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.
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'.