in reply to Re: Regex to grab data after the work "branch from"
in thread Regex to grab data after the work "branch from"

The error is gone but I dont see any data getting printed

p4filelog data below,$update_p4filelog has below data

//depot/asic/msmshared/users/QTVOEMDrops/qtv/player/audioplayer/file.cpp

... #2 change 1548905 edit on 2010/12/09 by sri@SRIXP (ktext) 'Audio loss when doing nultiple '

... #1 change 1548876 branch on 2010/12/09 by sri@SRIXP (ktext) 'Branching for orphan release fo'

... ... branch from //source/qcom/qct/multimedia/qtv/player/audioplayer/rel/1.1/src/file.cpp#1,#8

$update_p4filelog=`p4 filelog $1`; print "$update_p4filelog\n";# $update_base_branched_p4path = $update_p4filelog =~ /branch from(.*\/( +.*))\#\,(\#\d+)$/xmsg; print "$update_base_branched_p4path\n";# doesnt print anything,expecti +ng //source/qcom/qct/multimedia/qtv/player/audioplayer/rel/1.1/src/file.c +pp#8 to be printed

Replies are listed 'Best First'.
Re^3: Regex to grab data after the work "branch from"
by Anonymous Monk on Dec 14, 2010 at 07:18 UTC
    Maybe you should try to fix up the regex? use re 'debug';
      I created a sample script and used re 'debug',I really couldn't understand the output ...
      #!/usr/bin/perl use strict; use warnings; use Data::Dumper; use re 'debug'; my $file= "//depot/asic/msmshared/users/QTVOEMDrops/7600/3555473R/qtv/ +player/audioplayer/audiocmx.cpp"; my $update_p4where=`p4 where $file`; #print "$update_p4where"; my $update_p4filelog=`p4 filelog $file`; print "$update_p4filelog\n"; my $update_base_branched_p4path = $update_p4filelog =~ /branch\sfrom(. +*\/(.*))\#\,(\#\d+)$/xmsg; print "$update_base_branched_p4path\n";

      Compiling REx `branch from(.*/(.*))\#,(\#\d+)$' size 30 first at 1

      1: EXACT <branchfrom>(5) 5: OPEN1(7) 7: STAR(9) 8: SANY(0) 9: EXACT </>(11) 11: OPEN2(13) 13: STAR(15) 14: SANY(0) 15: CLOSE2(17) 17: CLOSE1(19) 19: EXACT <#,>(21) 21: OPEN3(23) 23: EXACT <#>(25) 25: PLUS(27) 26: DIGIT(0) 27: CLOSE3(29) 29: MEOL(30) 30: END(0)

      anchored `branch' at 0 floating `#,#' at 12..2147483647 (checking anchored) minlen 16

      //depot/asic/msmshared/users/QTVOEMDrops/7600/3555473R/qtv/player/audioplayer/audiocmx.cpp ... #2 change 1548905 edit on 2010/12/09 by c_krisri@C_KRISRIXP (ktext) 'Audio loss when doing nultiple ' ... #1 change 1548876 branch on 2010/12/09 by c_krisri@C_KRISRIXP (ktext) 'Branching for orphan release fo' ... ... branch from //source/qcom/qct/multimedia/qtv/player/audioplayer/rel/1.1/src/audiocmx.cpp#1,#8

      Guessing start of match, REx `branch\sfrom(.*/(.*))\#,(\#\d+)$' against `//depot/asic/msmshared/users/QTVOEMDrops/7600/3555473R/qtv/p...'...

      Found anchored substr `branch' at offset 219... Contradicts floating substr `#,#', giving up...//Why is it giving up?why isn't it goint to the next line??

      Match rejected by optimizer Freeing REx: `branch\sfrom(.*/(.*))\#,(\#\d+)$'

        use YAPE::Regex::Explain; print YAPE::Regex::Explain->new( qr/branch\sfrom(.*\/(.*))\#\,(\#\d+)$/xms )->explain __END__ The regular expression: (?msx-i:branch\sfrom(.*/(.*))\#\,(\#\d+)$) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?msx-i: group, but do not capture (with ^ and $ matching start and end of line) (with . matching \n) (disregarding whitespace and comments) (case-sensitive): ---------------------------------------------------------------------- branch 'branch' ---------------------------------------------------------------------- \s whitespace (\n, \r, \t, \f, and " ") ---------------------------------------------------------------------- from 'from' ---------------------------------------------------------------------- ( group and capture to \1: ---------------------------------------------------------------------- .* any character (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- / '/' ---------------------------------------------------------------------- ( group and capture to \2: ---------------------------------------------------------------------- .* any character (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- ) end of \2 ---------------------------------------------------------------------- ) end of \1 ---------------------------------------------------------------------- \# '#' ---------------------------------------------------------------------- \, ',' ---------------------------------------------------------------------- ( group and capture to \3: ---------------------------------------------------------------------- \# '#' ---------------------------------------------------------------------- \d+ digits (0-9) (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- ) end of \3 ---------------------------------------------------------------------- $ before an optional \n, and the end of a "line" ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------
Re^3: Regex to grab data after the work "branch from"
by Anonyrnous Monk (Hermit) on Dec 14, 2010 at 09:24 UTC
    .../file.cpp#1,#8 ^ ...\/(.*))\#\,(\#\d+)$/ ^

    You don't have anything in your regex that would match the 1.

      Thanks for pointing that out,now when I try to print it,I see a "1" getting printed,looks like its printing the number of times it matched,where am I going wrong?

      /branch\sfrom(.*\/(.*))\#\d+\,(\#\d+)$/xmsg;
        looks like its printing the number of times it matched

        In scalar context, the return value of the match indicates whether it matched.

        Fixing that, plus a number of other things, should leave you with something like

        my $update_p4filelog = "...xyz branch from //source/qcom/qct/multimedi +a/qtv/player/audioplayer/rel/1.1/src/file.cpp#1,#8"; my ($path, $ver) = $update_p4filelog =~ /branch from (.*\/.*)#\d+,(#\d ++)$/; my $update_base_branched_p4path = "$path$ver"; print "$update_base_branched_p4path\n";