php-regexHow to use PHP regex to match whitespace?
Using PHP regex to match whitespace is a simple task. The following example code block will match any whitespace character:
$regex = '/\s/';
The output of this code will be a boolean value of true if a whitespace character is found, and false if not.
Code explanation
-
\s: This is the regex pattern for matching whitespace characters. -
$regex: This is the variable that stores the regex pattern. -
/: These are the delimiters that enclose the regex pattern.
Helpful links
More of Php Regex
- How to use PHP regex to match a zip code?
- How to use PHP regex to match an exact string?
- How to remove non-printable characters using PHP regex?
- How to match a single quote in PHP regex?
- How to match a quotation mark in PHP regex?
- How to match a question mark in PHP regex?
- How to match one or more occurrences in PHP regex?
- How to use modifiers with PHP regex?
- How to get last matched occurrence in PHP regex?
- How to use PHP regex to match UUID?
See more codes...