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
 




Regular Expression Meta-character Whitespace "\s"


Topic

What is regular expression meta-character Whitespace "\s"?






Explanation

In Regular Expression, the meta-character "\s" is used to match any whitespace like space, tab, form feed etc.

PHP Example:
    <?php
    $emp = "empno is";
    if (preg_match("/\D{5}+\s{1}+\D{2}/", $emp))
     echo "Regex Pattern matches!";
    else 
     echo "Regex Pattern not matched!";
    ?>
Result:
    Pattern matches! 

In the above example the pattern "/\D{5}+\s{1}+\D{2}/", first matches for "5" non-digit characters, followed by "1" space then by "2" non-digit characters.

Perl Example:
    #! C:\programfiles\perl\bin\perl
    print "content-type: text/html\n\n";
    $name= "EMP.NOIS 123";
    if ($name =~ m/\s{2,3}/)
      {print "It's matched!";} 
    else 
      {print "It's not matched!";}
Result:
    It's not matched!

In the above example the pattern "\s{2,3}/" looks to match atleast "2" spaces upto "3" or more spaces, since the string has only "1" space it is matched.







A Note

Simple Regex Regular Expression Tutorial Online. We welcome your Valuable feedbacks or suggestions. This is a copyright content.


Other Links

web hosting