Perl Topics





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
Perl Tutorial
Introduction Introduction
Installing Perl Installing Perl
Basics of Perl Basics of Perl
Scalar Variables Scalar Variables
Operators Operators
Control Structures Control Structures
Lists Lists
Array Array
Arrays Manipulation Arrays Manipulation
Arrays Functons Array Functions
Hash Hash
Hash Functions Hash Functions
String Functions String Functions
Regular Expression Regular Expression
Regular Expression Functions Regular Expression Functions
Numerical Functions Numerical Functions
List Functions List Functions
User Defined Function User Defined Function
File Handling File Handling
Forums Ask Your Doubts
Feedback Feedback
 





Match Any Metacharacter in Perl


Tutorials Perl

Topic

What is Match Any Metacharacter in Perl?



Explanation

The "." metacharacter matches all characters except any newline characters in a multi-line string. If the "s" option of "m//s" is used, embedded newline characters will also be matched. This is convenient to match a pattern in multiple lines.

Example:
    #! C:\programfiles\perl\bin\perl
    print "content-type: text/html\n\n";
    if ("a\nb\nc" =~ m/a.b/)
     {
      print "matched the string a\nb\nc!\n";
     } 
    else 
     {
      print "no match in the string a\nb\nc!\n";
     }
    print "<br>";
    if ("a\nb\nc" =~ m/a.*c/s)
     {
      print "matched the string a\nb\nc!\n";
     }
    else 
     { 
       print "no match in the string a\nb\nc!\n";
     }
Result:
     no match in the string a b c!
     matched the string a b c! 

In the above example the string "a\nb\nc" is matched with the pattern m/a.*c/s, since the newline characters are present in between the pattern it gives a mismatch as m// does'nt match newline characters, but when the "s" option is used even if the embedded newline characters are present pattern is matched.






A Note
Simple introduction, basic CGI perl programming codes with examples. Do send your feedback or suggestions on this tutorial. This is a copyright content.

Other Links

web hosting