Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
PCRE (PHP <7.3)

/
(?:\s|^)([\-+]?)(?:(")([^"]+)"|(')([^']+)'|()(\S+))
/
gi

Description

A simple regexp to parse a search string.

It will split the search string into an array of search terms.

Each search term will be represented by an array containing 3 strings:

Index 0: A plus sign, minus sign or an empty string. You can use this to determine if the word is allowed, is not allowed or is reqiured to be matched.

Index 1: A single quote, double quote or an empty string. You can use this to identify quoted strings - "exact matches" - that should be given a higher relevance when matched.

Index 2: The word to match.

Submitted by @bananascript - 10 years ago