searchwp\tokens\regex_patterns
Da: 4.0.0
Indice
SearchWP cerca corrispondenze di pattern di espressioni regolari per mantenere intatte determinate stringhe ed evitare la tokenizzazione che potrebbe ridurne l'utilità durante la ricerca. Per impostazione predefinita, sono disponibili diversi pattern di espressioni regolari comuni per estrarre stringhe di SKU, date, iniziali, nomi di funzioni, numeri di versione e altro.
Puoi usare questo hook per aggiungere le tue corrispondenze di pattern.
Nota: I pattern devono essere forniti in ordine di rigidità; prima quelli più rigidi.
I pattern predefiniti sono i seguenti:
| [ | |
| // Function names, including namespaced function names. | |
| "/([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*(\\\\[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)*)\(/is", | |
| // Date formats. | |
| '/\b([0-9]{4}-[0-9]{1,2}-[0-9]{1,2})\b/is', // YYYY-MM-DD | |
| '/\b([0-9]{1,2}-[0-9]{1,2}-[0-9]{4})\b/is', // MM-DD-YYYY | |
| '/\b([0-9]{4}\\/[0-9]{1,2}\\/[0-9]{1,2})\b/is', // YYYY/MM/DD | |
| '/\b([0-9]{1,2}\\/[0-9]{1,2}\\/[0-9]{4})\b/is', // MM/DD/YYYY | |
| // IP addresses. | |
| '/\b(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})\b/is', // IPv4. | |
| // Initials. | |
| "/\\b((?:[A-Za-z]\\.\\s{0,1})+)/isu", | |
| // Version numbers: 1.0 or 1.0.4 or 1.0.5b1. | |
| '/\b([a-z0-9]+(?:\\.[a-z0-9]+)+)\b/is', | |
| // Serial numbers. | |
| '/(?=\S*[\-\_])([[:alnum:]\-\_]+)/ius', // Hyphen/underscore separator. | |
| // Strings followed by digits and maybe strings. | |
| // e.g. `System 1` or `System 12ab-cd12` | |
| '/([A-Za-z0-9]{1,}\s[0-9]{1,}[A-Za-z0-9]*)/iu', | |
| // Strings of digits. | |
| "/\\b(\\d{1,})\\b/is", | |
| // e.g. M&M, M & M. | |
| "/\\b([[:alnum:]]+\\s?(?:&\\s?[[:alnum:]]+)+)\b/isu", | |
| // Strings with apostraphe(s). Consider both standard and curly. | |
| '/\b([a-z0-9]*[\'|’][a-z0-9]*)\b/isu' | |
| ] |
Parametri
| Tipo | Parametro | Predefinito | Da |
|---|---|---|---|
| Stringa{} | $patterns |
Vedi gist sopra | 4.0.0 |
Esempi
All hooks should be added to your custom SearchWP Customizations Plugin.
Aggiungi pattern di espressione regolare personalizzato
| <?php | |
| // Add custom regular expression pattern to SearchWP. | |
| add_filter( 'searchwp\tokens\regex_patterns', function( $patterns ) { | |
| $my_patterns = [ | |
| "/([0-9]{1,2}\\/[0-9]{1,2})/is", // Retain measurement details. | |
| ]; | |
| // We want our pattern to be considered top priority. | |
| return array_merge( $my_patterns, $patterns ); | |
| } ); |

