OsRegexIsMatch

From OpenSimulator

(Difference between revisions)
Jump to: navigation, search
m (Added note stating which version of OpenSim introduced this function)
m (See Also: Small change)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
{{osslfunc
 
{{osslfunc
|function_syntax=LSLInteger osRegexIsMatch(String input, String pattern)
+
|function_syntax=integer osRegexIsMatch(string input, string pattern)
 
|threat_level=Low
 
|threat_level=Low
 
|permissions=true
 
|permissions=true
 
|delay=0
 
|delay=0
 
|description=Returns 1 if the input string matches the regular expression pattern. Wraps to Regex.IsMatch()
 
|description=Returns 1 if the input string matches the regular expression pattern. Wraps to Regex.IsMatch()
 +
|ossl_example=<source lang = "lsl">
 +
//
 +
// osRegexIsMatch Script Example
 +
// Author: djphil
 +
//
 +
 +
string check_string(string input, string pattern)
 +
{
 +
    if (osRegexIsMatch(input, pattern))
 +
    {
 +
        return "The input string \"" + input + "\" matches with the regular expression pattern \"" + pattern + "\"";
 +
    }
 +
   
 +
    else
 +
    {
 +
        return "The Input string \"" + input + "\" do not matches with the regular expression pattern \"" + pattern + "\"";
 +
    }
 +
}
 +
 +
default
 +
{
 +
    state_entry()
 +
    {
 +
        llSay(PUBLIC_CHANNEL, "Touch to see osRegexIsMatch usage.");
 +
    }
 +
 +
    touch_start(integer number)
 +
    {
 +
        // Check lowercase from a to z
 +
        llSay(PUBLIC_CHANNEL, check_string("abcdef", "[a-z]"));
 +
        llSay(PUBLIC_CHANNEL, check_string("ABCDEF", "[a-z]"));
 +
        llSay(PUBLIC_CHANNEL, check_string("123456", "[a-z]"));
 +
 +
        // Check uppercase from A to Z
 +
        llSay(PUBLIC_CHANNEL, check_string("abcdef", "[A-Z]"));
 +
        llSay(PUBLIC_CHANNEL, check_string("ABCDEF", "[A-Z]"));
 +
        llSay(PUBLIC_CHANNEL, check_string("123456", "[A-Z]"));
 +
 +
        // Check numbers from 0 to 9
 +
        llSay(PUBLIC_CHANNEL, check_string("abcdef", "[0-9]"));
 +
        llSay(PUBLIC_CHANNEL, check_string("ABCDEF", "[0-9]"));
 +
        llSay(PUBLIC_CHANNEL, check_string("123456", "[0-9]"));
 +
    }
 +
}
 +
</source>
 
|additional_info=This function was added in 0.7.5-post-fixes
 
|additional_info=This function was added in 0.7.5-post-fixes
 
}}
 
}}
Line 10: Line 55:
 
== See Also ==
 
== See Also ==
 
* [[osListenRegex]]
 
* [[osListenRegex]]
 +
* [[osRegexIsMatch]]

Latest revision as of 01:58, 13 December 2020

integer osRegexIsMatch(string input, string pattern)
Returns 1 if the input string matches the regular expression pattern. Wraps to Regex.IsMatch()
Threat Level Low
Permissions Use of this function is always allowed by default
Extra Delay 0 seconds
Example(s)
//
// osRegexIsMatch Script Example
// Author: djphil
//
 
string check_string(string input, string pattern)
{
    if (osRegexIsMatch(input, pattern))
    {
        return "The input string \"" + input + "\" matches with the regular expression pattern \"" + pattern + "\"";
    }
 
    else
    {
        return "The Input string \"" + input + "\" do not matches with the regular expression pattern \"" + pattern + "\"";
    }
}
 
default
{
    state_entry()
    {
        llSay(PUBLIC_CHANNEL, "Touch to see osRegexIsMatch usage.");
    }
 
    touch_start(integer number)
    {
        // Check lowercase from a to z
        llSay(PUBLIC_CHANNEL, check_string("abcdef", "[a-z]"));
        llSay(PUBLIC_CHANNEL, check_string("ABCDEF", "[a-z]"));
        llSay(PUBLIC_CHANNEL, check_string("123456", "[a-z]"));
 
        // Check uppercase from A to Z
        llSay(PUBLIC_CHANNEL, check_string("abcdef", "[A-Z]"));
        llSay(PUBLIC_CHANNEL, check_string("ABCDEF", "[A-Z]"));
        llSay(PUBLIC_CHANNEL, check_string("123456", "[A-Z]"));
 
        // Check numbers from 0 to 9
        llSay(PUBLIC_CHANNEL, check_string("abcdef", "[0-9]"));
        llSay(PUBLIC_CHANNEL, check_string("ABCDEF", "[0-9]"));
        llSay(PUBLIC_CHANNEL, check_string("123456", "[0-9]"));
    }
}
Notes
This function was added in 0.7.5-post-fixes


[edit] See Also

Personal tools
General
About This Wiki