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()

Parameters

ColumnTypeDefaultDescription
$keyword: string
'.*?'
$keyword;

Location

include/search_functions.php lines 3307 to 3323

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 30th October 2025 20:35 Europe/London time based on the source file dated 30th October 2025 16:05 Europe/London time.