php-regexHow to use the "s" modifier in PHP regex?
The "s" modifier in PHP regex is used to make the dot (.) character match all characters, including newline characters. This allows the regex to match across multiple lines.
Example code
$string = "This is a
multiline string";
$pattern = "/This.*string/s";
if (preg_match($pattern, $string)) {
echo "Match found!";
}
Output example
Match found!
Code explanation
$string
: This is the string that the regex will be applied to.$pattern
: This is the regex pattern that will be used to match against the string. Thes
modifier is used to make the dot (.) character match all characters, including newline characters.preg_match()
: This is the PHP function used to apply the regex pattern to the string.
Helpful links
More of Php Regex
- How to use PHP regex to match an exact string?
- How to use PHP regex with zero or more occurrences?
- How to use PHP regex to match a nbsp HTML whitespace?
- How to use PHP regex to match a boolean value?
- How to use PHP regex with the "x" modifier?
- How to match strings starting with a certain string using PHP regex?
- How to use PHP regex to match whitespace?
- How to use PHP regex to match UUID?
- How to use PHP regex to match UTF8?
- How to match a space using PHP regex?
See more codes...