preg_match如果字符串包含+或 -

How to validate if a string contain either + or - ??

preg_match('[\-\+]', '(292+3)*1', $match);
print_r($match);

preg_match('[\-\+]', '(292-3)*1', $match);
print_r($match);

output

Array
(
)
Array
(
)

Regex must be between delimiters:

preg_match('/[-+]/', '(292+3)*1', $match);

You could do this without regex.

Use strpos() function.

$str = '+123-';

if (strpos($str, '+') !== FALSE || strpos($str, '-') !== FALSE) {
     echo 'Found it';
} else {
     echo 'Not found.';
}

Hope this helps.