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
 





Backtracking in Regular Expression


Tutorials Perl

Topic

What is Backtracking in Regular Expression?



Explanation

Storing the matching patterns for future use is known as Backtracking.

Example:
    #! C:\programfiles\perl\bin\perl
    print "content-type: text/html\n\n";
    $string = '17-12-76 12:30:15';
    if ($string =~m/([0-9]+-[0-9]+-[0-9]+) ([[0-9]+:[0-9]+:[0-9]+)/)
    {
     print "The Date of Birth is '$1'.\n";
     print "<br>";
     print "The Date is '$2'.\n";
    }
Result:
    The Date of Birth is '17-12-76'.
    The Date is '12:30:15'. 

In the above example, we have two matching patterns one for the date, then for a time, and the values returned when there is a match can be referred anywhere using "$1" for the first pattern, "$2" for the second pattern.






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