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
 




Carriage return metacharacter "\r" in Regular Expression


Tutorials Regular-expression

Topic

How is metacharacter "\r" used in regular expression?




Explanation

In regex, "\r" metacharacter is used to match carriage return in a string.

PHP Example:
    <?php
    $str = "hiox	
             india";
    if (preg_match("/\r/", $str, $matches))
     echo "Pattern matches!";
    else 
    echo "Pattern not matched!";
    ?>
Result:
    Pattern matches!

In the above regex example the string "$str" has a carriage return, to the next line, so it is matched.

Perl Example:
    #! C:\programfiles\perl\bin\perl
    print "content-type: text/html\n\n";
    $str = "hi how are you";
    if ($str =~ m/\r/)
     {print "It's matched!";} 
    else 
     {print "It's not matched!";}
Result:
    It's not matched!

In the above "\r" metacharacter example for regex, there are no "carriage return" in the string, so its 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