Thursday, October 8, 2020

compare regular expression on rAthena & Hercules

The most famous script that uses Regular Expression is GmOcean's Disguise Event
to learn more about Regular Expression, refer to Wikipedia
Visit this site for more in-depth tutorial

This NPC will Copy whatever you type
It's common practice that you should include ^ at the beginning and $ at the end
without it, players can input whitespace to bypass the check

Example:
(.@a$ ~= "asdf") = it can be "asdf", "aaasdf", "asdfffff", " asdf   " and so on
(.@a$ ~= "^asdf") = it can be "asdf", "asdffffff", "asdfasdf", "asdf   " <-- this just check the begining string
(.@a$ ~= "^asdf$") = it can only be "asdf", no other match

defpattern 1, "([^:]+): asdf","L_0"; <-- it can be "asdf", "asdfffffff", "asdfasdf", "asdf    " and so on
defpattern 1, "([^:]+): asdf$","L_0"; <-- only "asdf" will trigger the label L_0, OR "ASDF", "AsDf" and so on ...

yup, *pcre_match is case-sensitive, but *defpattern isn't, remember to keep this in mind
to make *pcre_match case-insensitive, use (?i) flag
to make *defpattern case-sensitive, use (?-i) flag


in practice, this command is most useful to check invalid character input
- only allow 0-9, a-z, A-Z or follow a format, like MySQL datetime format

for rAthena counterpart, rAthena has *preg_match instead, which follow PHP style input
However unlike Hercules, there are no way to capture the strings within a bracket
rAthena's *preg_match can only returns 0 or 1
correct me if I'm wrong, the source code seems to indicate it can return 0~10 but I couldn't get it display 2 or above



Some older client that diff with multi-language support will return |00 in front of character speech
try check it with *consolemes with the very first script (rAthena is *debugmes)
if that happens, your syntax has to change into


External Links:
Disguise Event fix
defpattern regexp
ignore case sensitive in regexp

No comments:

Post a Comment

Linux compiler error that never shown on Visual Studio

let's just admit Visual Studio sux ... ok ? right now, if you want to host a Private Ragnarok Online server, its just better to choose...