This Documentation is for SearchWP Version 3

Available since: 1.9


View Parameters »

Note: Use of this hook will require a manual reindex

SearchWP is a token-based indexer and search algorithm. That means that all content is tokenized and broken up by both whitespace and special characters. To avoid breaking apart specially formatted strings like SKUs, version numbers, and dates, SearchWP implements the idea of a Regex Whitelist. The Regex Whitelist is an array of regular expression patterns that the indexer uses to extract content before it gets tokenized.

The default regex patterns are as follows (they are ordered from most strict to least strict):

private $term_pattern_whitelist = array(
// these should go from most strict to most loose
// functions
// Date formats
"/([0-9]{4}-[0-9]{1,2}-[0-9]{1,2})/is", // date: YYYY-MM-DD
"/([0-9]{1,2}-[0-9]{1,2}-[0-9]{4})/is", // date: MM-DD-YYYY
"/([0-9]{4}\\/[0-9]{1,2}\\/[0-9]{1,2})/is", // date: YYYY/MM/DD
"/([0-9]{1,2}\\/[0-9]{1,2}\\/[0-9]{4})/is", // date: MM/DD/YYYY
// IP
"/(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})/is", // IPv4
// initials
// version numbers: 1.0 or 1.0.4 or 1.0.5b1
// serial numbers
"/(\\b[-_]?[0-9a-zA-Z]+(?:[-_]+[0-9a-zA-Z]+)+[-_]?)/isu", // hyphen/underscore separator
// strings of digits
// e.g. M&M, M & M
view raw gistfile1.php hosted with ❤ by GitHub

If you would like to modify the Regex Whitelist, add something like the following to your theme’s functions.php while retaining the more-strict-to-less-strict order:

function my_searchwp_term_pattern_whitelist( $whitelist ) {
$my_whitelist = array(
"/\\b(IT)\\b/u", // always keep "IT" (all caps only!)
// we want our pattern to be considered the most specific
// so that false positive matches do not interfere
$whitelist = array_merge( $my_whitelist, $whitelist );
return $whitelist;
add_filter( 'searchwp_term_pattern_whitelist', 'my_searchwp_term_pattern_whitelist' );
view raw gistfile1.php hosted with ❤ by GitHub


Parameter Type Description
$patterns Array

Regular expression patterns to match against from most strict to least strict

[wpforms id="3080"]