Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test functions

prepare_regex_search_string()

Description

Escape and process a string from ResourceSpace search syntax to regex syntax
Wildcards are replaced with '.?' - any character 0 or more times
Multiple keyword matches are split into an OR group
Word boundaries are added to avoid unintended wildcards.

Parameters

ColumnTypeDefaultDescription
$keyword: string
'.*?'
$keyword;
$keyword string Keyword string without any field names or special search strings

Return

string Processed string ready for RLIKE searches

Location

include/search_functions.php lines 3316 to 3332

Definition

 
function prepare_regex_search_string(string $keyword): string
{
    
$keyword preg_quote($keyword);
    
$keyword str_replace('\*''.*?'$keyword);
    
$keywords explode(";"$keyword);
    if (
count($keywords) > 1) {
        
$keyword '(' implode("|"$keywords) . ')';
    }
    if (
preg_match('/\w/'$keyword) === 0) {
        
// Use lookaheads/lookbehinds for boundary-like behavior when the keyword consists of non-word characters (e.g. ,, &, -)
        // because \b only works for transitions between word characters (letters, digits, _) and non-word characters.
        
$keyword "(?<!\w)" $keyword "(?!\w)";
    } else {
        
$keyword "\\b" $keyword "\\b";
    }
    return 
$keyword;
}

This article was last updated 20th November 2025 20:35 Europe/London time based on the source file dated 10th November 2025 12:10 Europe/London time.