User Tools

Site Tools



This shows you the differences between two versions of the page.

Link to this comparison view

rmatch [2006/08/29 20:18] (current)
Line 1: Line 1:
 +# $EPIC: rmatch.txt,​v 1.5 2006/08/29 18:22:56 sthalik Exp $
 +$__rmatch__(<​word>​ <pattern list>)
 +   * If the <​word>​ argument is omitted the empty string is returned.
 +   * <pattern list> contains zero or more space separated "​extended words"
 +   * Each pattern in <pattern list> is taken as a wildcard pattern, which is matched against <​word>,​ which is taken as literal text.
 +   * If none of the patterns in <pattern list> match <​word>,​ then the return value of $__rmatch__() is 0 (zero).
 +   * Otherwise, the return value is the word from <pattern list> for the pattern which "​best"​ matches <​word>​. ​ A pattern'​s "​value"​ is the number of literal (non-wildcard) characters it contains. ​ The pattern that matches <​word>​ and has the most "​value"​ is the "​best"​ match.
 +   * The return value begins counting words FROM ONE, like [[match]]. ​ You will have to subtract one from the return value before using it in some other functions, like $[[word]]().
 +   * If none of the patterns in <pattern list> contain wildcards, then you should use the $[[findw]]() function instead.
 +   * If <pattern list> contains only one word, you should use the =~ operator instead.
 +This function can be used to match a bunch of patterns against a single
 +literal word.  This is often used to match the $[[userhost
 +function|userhost]]() value against a list of userhosts in an access
 +list.  Since ircII does not include the =~ operator, this was the
 +standard way to do pattern matching on one word against one string in
 +scripts. ​ Also, since ircII does not include the $[[findw]]() function,
 +this was the standard way to determine if a literal word was present in
 +a literal word list.  The $__rmatch__() function is still generally
 +useful for matching one word against a list of patterns.
 + ​0 ​  no matches found
 +>0   index to "​best"​ pattern in list -- counting from one!
 +$rmatch(one o* t* f*)       ​returns 1
 +$rmatch(one z* t* f*)       ​returns 0
 +$rmatch(one o* on* t* f*)   ​returns 2
 +This function first appeared in ircII.
rmatch.txt ยท Last modified: 2006/08/29 20:18 (external edit)