[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Regex trouble
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Regex trouble

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


Posted by Poromenos   Greece  (1,037 posts)  [Biography] bio
Date Thu 25 Nov 2004 05:21 PM (UTC)

Amended on Thu 25 Nov 2004 05:22 PM (UTC) by Poromenos

Message
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]]]

Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it!
[Go to top] top

Posted by Nick Gammon   Australia  (21,647 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Thu 25 Nov 2004 06:38 PM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Poromenos   Greece  (1,037 posts)  [Biography] bio
Date Reply #2 on Thu 25 Nov 2004 06:55 PM (UTC)
Message
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(\|.+?)+\]

Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it!
[Go to top] top

Posted by Nick Gammon   Australia  (21,647 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Thu 25 Nov 2004 07:56 PM (UTC)
Message
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


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Somegirl   (33 posts)  [Biography] bio
Date Reply #4 on Thu 25 Nov 2004 08:08 PM (UTC)
Message
Will this always be a address|title?
if so, why not use
LINK\|([a-zA-Z.]+)\|([a-zA-Z ]+)
[Go to top] top

Posted by Poromenos   Greece  (1,037 posts)  [Biography] bio
Date Reply #5 on Thu 25 Nov 2004 09:10 PM (UTC)
Message
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

Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it!
[Go to top] top

Posted by Nick Gammon   Australia  (21,647 posts)  [Biography] bio   Forum Administrator
Date Reply #6 on Thu 25 Nov 2004 11:52 PM (UTC)
Message
Well, my solution works. The extra set of brackets around the whole thing.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Somegirl   (33 posts)  [Biography] bio
Date Reply #7 on Fri 26 Nov 2004 10:30 AM (UTC)

Amended on Fri 26 Nov 2004 10:32 AM (UTC) by Somegirl

Message
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.
[Go to top] top

Posted by Flannel   USA  (1,230 posts)  [Biography] bio
Date Reply #8 on Fri 26 Nov 2004 09:35 PM (UTC)
Message
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.

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
[Go to top] 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.


5,311 views.

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

Go to topic:           Search the forum


[Go to top] 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.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]