Non-whitespace "S" metacharacter in Regex.

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 = "nnnnn";
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:programfilesperlbinperl
print "content-type: text/htmlnn";
$name= "rrnnttfff";
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.

Ask Questions

Ask Question