9951 explained code solutions for 126 technologies


php-regexHow to match a plus sign in PHP regex?


The plus sign + can be matched in PHP regex using the \+ escape sequence.

$string = 'This is a + sign';

if (preg_match('/\+/', $string)) {
    echo 'Match found';
}

Output example

Match found

The \+ escape sequence is used to match the literal + character in a regex pattern.

Code explanation

  • \+: escape sequence used to match the literal + character in a regex pattern

Helpful links

Edit this code on GitHub