|
|
Non-whitespace "\S" metacharacter in Regex.
|
Tutorials

Regular-expression

|
Topic |
How is "\S" used for regular expression in PHP?
|
|
Explanation |
|
The "\S" character is used to match any non-whitespace characters in regex.
PHP Example:
<?php
$emp = "\n\nn\n\n";
if (preg_match("/\S/", $emp, $matches))
{echo "Pattern matches!";
print "<br>"
echo $matches[0];}
else
echo "Pattern not matched!";
?>
Result:
Pattern matches!
n
In the above example for regular expression there are "\n" characters with an alphabet "n" so
non-whitespace characters are matched.
Perl Example:
#! C:\programfiles\perl\bin\perl
print "content-type: text/html\n\n";
$name= "\r\r\n\n\t\t\f\f\f";
if ($name =~ m/\S/)
{print "It's matched!";}
else
{print "It's not matched!";}
Result:
It's not matched!
In the above example for regex there are only whitespace characters, so non-whitespace characters are unmatched.
|
| A Note |
Simple Regex Regular Expression Tutorial Online. We welcome your Valuable feedbacks or suggestions. This is a copyright content.
|
|
|
|