function _is_regex in Slickgrid 7.2
Helper function Returns TRUE if $str is a regular expression, according to the following rules:
- Does the string start and end with the same character? (non alphanumeric, excluding whitespaces and backslashes)
- Does the string contain "*" or or '?' or '$' or '^' or "[" and "]"?
1 call to _is_regex()
- slickgrid_get_data in includes/
slickgrid.getdata.inc - Return the data for a dynamically loaded SlickGrid.
File
- includes/
slickgrid.getdata.inc, line 244
Code
function _is_regex($str) {
$first_char = substr($str, 0, 1);
$last_char = substr($str, -1);
// You can use any non alphanumeric delimiter (excluding whitespaces and backslashes)
if (strlen($str) < 3 || $first_char != $last_char || ctype_alnum($first_char) || $first_char == " " || $first_char == "\\") {
return false;
}
// Look for 'special' characters and return true if found
$str = substr($str, 1, -1);
if (strpos($str, '[') !== false && strpos($str, ']') !== false) {
return true;
}
elseif (strpos($str, '*') !== false) {
return true;
}
elseif (strpos($str, '?') !== false) {
return true;
}
elseif (strpos($str, '$') !== false) {
return true;
}
elseif (strpos($str, '^') !== false) {
return true;
}
else {
return false;
}
}