in reply to Re: Pattern matching and deriving the data between the "(double quotes) in HTML tag
in thread Pattern matching and deriving the data between the "(double quotes) in HTML tag

Hi AnomalousMonk, Thanks for the comment. I understood that the problem was with the g - global modifier in the patters m//g. I achieved the desired output: 2016-09-30T00:00:00,2016-12-28T23:59:59 by using the below code.

#/usr/bin/perl use strict; use warnings; my $timeLimit = '<timeLimit endTime="2016-12-28T23:59:59" startTime="2 +016-09-30T00:00:00"></timeLimit>'; $timeLimit =~ m/startTime="(.*?)"/g; my $startTime = $1; chomp($timeLimit); my $endTime =''; if ($timeLimit =~ m/endTime/) { $timeLimit =~ m/endTime="(.*?)"/; $endTime = $1; } print "[$startTime],[$endTime]\n";
  • Comment on Re^2: Pattern matching and deriving the data between the "(double quotes) in HTML tag
  • Download Code

Replies are listed 'Best First'.
Re^3: Pattern matching and deriving the data between the "(double quotes) in HTML tag
by AnomalousMonk (Archbishop) on Dec 06, 2016 at 13:32 UTC

    It's good that you've found a solution to your problem, but you should realize that the  /g match modifier in the
        $timeLimit =~ m/startTime="(.*?)"/g;
    statement does nothing more than pose a potential pitfall for future code, either in execution or development. Why leave it in?

    Also, please pay attention to other replies advocating an XML-parsing approach to what is essentially XML.

    And if you choose to stick with regexes, please consider kcott's wise advice here about using  ([^"]*) to capture the unescaped body of a double-quoted string.


    Give a man a fish:  <%-{-{-{-<