Regular Expression





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
Regex Topics
Introduction Introduction
Common Metacharacter Common Metacharacter's
Metacharacters Metacharacter's
Qualifiers Quantifier's
Word Boundry Word Boundry
Non-word Boundry Non-word Boundry
POSIX Character Classes POSIX-Character Classes
Feedback Feedback
Forums Ask Your Doubts
 




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.


Other Links

web hosting