Regex trouble

Posted by Poromenos on Thu 25 Nov 2004 05:21 PM — 9 posts, 31,253 views.

Greece #0
I know this is not MC per se, but I'm going crazy. Could someone please tell me why this matches "my page" for %1 and nothing for %2?
\[\[\[\?LINK(?:\|(.*?))+\]\]\]
The text is [[[?LINK|poromenos.org|my page]]]
Amended on Thu 25 Nov 2004 05:22 PM by Poromenos
Australia Forum Administrator #1
You have only one capturing sequence there. Round brackets capture, of which you have two sets, however (:? something) says not to capture. You have that in front of one of them.
Greece #2
That's not the problem, I want to capture the internal one. It always returns the last one, no matter how many I have, and even this won't work:
LINK(\|.+?)+\]
Australia Forum Administrator #3
Hmmm, interesting. Take out the "ungreedy" question mark and it works better:


<triggers>
  <trigger
   custom_colour="2"
   enabled="y"
   match="\[\[\[\?LINK(?:\|(.*))+\]\]\]"
   regexp="y"
   send_to="2"
   sequence="100"
  >
  <send>%%1 = %1
%%2 = %2</send>
  </trigger>
</triggers>


My output for that one:


%1 = poromenos.org|my page
%2 =


Or for the second one do the same thing or add another set of brackets:


<triggers>
  <trigger
   custom_colour="2"
   enabled="y"
   match="LINK((\|.+?)+)\]"
   regexp="y"
   send_to="2"
   sequence="100"
  >
  <send>%%1 = %1
%%2 = %2</send>
  </trigger>
</triggers>


My output for that one:


%1 = |poromenos.org|my page
%2 = |my page

#4
Will this always be a address|title?
if so, why not use
LINK\|([a-zA-Z.]+)\|([a-zA-Z ]+)
Greece #5
No, Somegirl, it has to be able to match any number of parameters. After talking to some Perl experts, I have found out that this can't be done, because it will always return the last match. I have finally found something regex can't do! :P
Australia Forum Administrator #6
Well, my solution works. The extra set of brackets around the whole thing.
#7
Right! This is very similar to what I was trying to do in the other thread. Matching multiple things in the same line. You can only capture the last or first thing because it will only match once per line. What Nick did works because it basically captures the whole string then the %2 is a submatch on one thing inside the string. I've just settled on sending the whole line to scripting to get what I want.

Now a lot more of the crazy RegExp documentation included with Mushclient makes sense.
Amended on Fri 26 Nov 2004 10:32 AM by Somegirl
USA #8
You can make it match multiple times on a line. But the script will only get called once.
Try coloring something multiple times on a line. It works.