[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]  Lua
. . -> [Subject]  a Test with 'rex_pcre' lib..
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

a Test with 'rex_pcre' lib..

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


Posted by Maxhrk   USA  (76 posts)  [Biography] bio
Date Mon 24 Dec 2007 10:37 PM (UTC)

Amended on Tue 25 Dec 2007 04:08 PM (UTC) by Maxhrk

Message
This experiment that i want to find out how good Rex_pcre lib is... since it probably very new library. Nevertheless I found something interesting while playing with this kind of experiment.

Also this experiment also including by go against mushclient's trigger's regex pattern matching.


the regex line would be this:


"\((?P<channel>.+)\): (?P<who>.+?)(| \((?P<where>.+)\)) say(|s), \"(?P<comment>.+)\"


and trigger line is thus:

(Serenwilde): You say, "Hmmhmm."


the
this is lua code i use to check the wildcards. as usual everybody no doubt everybody use it anyway!


for key, value in pairs(wildcards) do
		if type(value) == "boolean" then
			print("KEY:" .. key .. "  value:" .. tostring(value))
		else
			print("KEY:" .. key .. "  value:" .. value)
		end --if
	end --if



mushclient's wildcards match:

(Serenwilde): You say, "Hmmhmm."
KEY:1  value:Serenwilde
KEY:2  value:You
KEY:3  value:
KEY:4  value:
KEY:5  value:
KEY:6  value:Hmmhmm.
KEY:comment  value:Hmmhmm.
KEY:channel  value:Serenwilde
KEY:0  value:(Serenwilde): You say, "Hmmhmm."
KEY:who  value:You
KEY:where  value:


rex_pcre lib's wildcards match:

id:1  v:(Serenwilde)
id:2  v:(Serenwilde)
id:3  v:You
id:4  v:
id:5  v:false
id:6  v:false
id:7  v:s
id:8  v:Hmmhmm.
id:who  v:You
id:where  v:false
id:comment  v:Hmmhmm.
id:channel  v:(Serenwilde)


notice the difference? it's the channel wildcard. In fact I was expect it to be just 'Serenwilde' not '(Serenwilde)'


The the version of rex_pcre library i am using is 2.2. Just a thought!
[Go to top] top

Posted by Nick Gammon   Australia  (21,406 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Tue 25 Dec 2007 09:04 AM (UTC)
Message
Can you clarify which rex_pcre library you are referring to? There is an inbuilt PCRE matcher in MUSHclient (virtually unchanged from the one from the PCRE web site), which is used in both trigger and alias matching, as well as the inbuilt "rex" library, see this link:

http://www.gammon.com.au/scripts/doc.php?general=lua_rex

There is also the Lua regular expression matching which is something different again.

Now you mention rex_pcre, is that a DLL you got from a Lua site? If so it is possibly a different version of PCRE to the one I am using. The presence of the parentheses is puzzling however.

- Nick Gammon

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

Posted by Maxhrk   USA  (76 posts)  [Biography] bio
Date Reply #2 on Tue 25 Dec 2007 04:06 PM (UTC)
Message
oh mushclient has builtin pcre function? i better try this out then!
[Go to top] top

Posted by Maxhrk   USA  (76 posts)  [Biography] bio
Date Reply #3 on Tue 25 Dec 2007 04:24 PM (UTC)

Amended on Tue 25 Dec 2007 06:32 PM (UTC) by Maxhrk

Message
here is mushclient's builtin rex test:


key:1  value:(Serenwilde)
key:2  value:(Serenwilde)
key:3  value:You
key:4  value:
key:5  value:false
key:6  value:false
key:7  value:
key:8  value:Hmmhmm.
key:who  value:You
key:where  value:false
key:comment  value:Hmmhmm.
key:channel  value:(Serenwilde)


AMEND:

well well that is interesting. i decide to add extra '\' beside other backslash like this:


"\\((?P<channel>.+)\\): (?P<who>.+?)(| \\((?P<where>.+)\\)) say(|s), \"(?P<comment>.+)\""


key:1 value:Serenwilde
key:2 value:You
key:3 value:
key:4 value:false
key:5 value:false
key:6 value:
key:7 value:Hmmhmm.
key:who value:You
key:where value:false
key:comment value:Hmmhmm.
key:channel value:Serenwilde

AMEND(last time):
I tried to do same with rex_pcre, it seem got a right value. I guess i have to put double backslash next time to have a correct value. :p


P.S. Merry Christmas. :)
[Go to top] top

Posted by Nick Gammon   Australia  (21,406 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Tue 25 Dec 2007 08:29 PM (UTC)
Message
You need to be cautious with backslashes in the "send" field of triggers and aliases in MUSHclient.

MUSHclient automatically handles things like \n in the Send field and translates them into a linefeed. Thus, to actually send \ you need to put \\ there.

However if using Lua scripting, Lua also turns \\ into \, so to do something like a Note that notes a single \, and using "send to script" you actually have to do this:

Note ("\\\\")

MUSHclient converts \\\\ to \\ before handing it off to Lua, and Lua converts \\ to \, which is what gets printed.

This makes doing PCRE regular expressions a bit fiddly. One way is to use the script file (rather than "send to script") which halves the number of backslashes you need.

Then inside the script file, if you need to make a regular expression you could use multi-line comments, which then removes the need to escape backslashes at all. For example:

myregexp = [[ ..... put it here ...... ]]

- Nick Gammon

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

Posted by Nick Gammon   Australia  (21,406 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Tue 25 Dec 2007 08:30 PM (UTC)
Message
Incidentally, Lua regular expressions use % as a special character (eg. %a for alphabetic characters) thus getting around the need to double the number of backslashes in quoted strings.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[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.


4,605 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]