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
More of Php Regex
- How to use PHP regex to match special characters?
- How to use PHP regex with zero or more occurrences?
- How to use PHP regex to match an exact string?
- How to use PHP regex in a case insensitive mode?
- How to use PHP regex to match a nbsp HTML whitespace?
- How to use PHP regex to match tab?
- How to use PHP regex with the "x" modifier?
- How to use PHP regex to get a YouTube video ID?
- How to use PHP regex to match whitespace?
- How to use PHP regex to match UUID?
See more codes...