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 a nbsp HTML whitespace?
- How to use PHP regex to match special characters?
- How to use PHP regex to match a zip code?
- 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 to match UUID?
- How to use PHP regex to match an XML tag?
- How to match a single quote in PHP regex?
- How to use PHP regex to match a URL in a href attribute?
- How to use PHP regex to match whitespace?
See more codes...