Non-whitespace "S" metacharacter in Regex.

How is "S" used for regular expression in PHP?


The "S" character is used to match any non-whitespace characters in regex.

PHP Example:

$emp = "nnnnn";
if (preg_match("/S/", $emp, $matches))
{echo "Pattern matches!";
print "<br>"
echo $matches[0];}
echo "Pattern not matched!";
Result :

Pattern matches!

In the above example for regular expression there are "n" characters with an alphabet "n" so non-whitespace characters are matched.

Perl Example:

#! C:programfilesperlbinperl
print "content-type: text/htmlnn";
$name= "rrnnttfff";
if ($name =~ m/S/)
{print "It's matched!";}
{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.

Ask Questions

Ask Question