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 New Line "\n"


Topic

What is regular expression meta-character New Line "\n"?




Explanation

In Regular Expression, the meta-character "\n" is used to match the new line character.

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

In the above example the pattern "/\D{5}(\n{1})?$/",first part "\D{5}" matches a string with "5" characters ,the second part or the sub pattern macthes a single "\n" character, since the "?" even a match occurs not matter "\n" is present or not.

Perl Example:
    #! C:\programfiles\perl\bin\perl
    print "content-type: text/html\n\n";
    $name= "ander\n";
    if ($name =~ m/\D{5}\n$/)
      {print "It's matched!";} 
    else 
      {print "It's not matched!";}
Result:
    It's matched!

In the above example the pattern matches for exactly "5" non digit characters and should end with a "\n" character and in the example the string matches.





A Note

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


Other Links

web hosting