0

need to fetch job id from this huge string(1618252) and no regexp to do this operation as it may fail when job id is not found----------

% set invoc [[$this cget -testrun] cget -invocation]
tcl profilemgr -configNetwork {} -startBefore now -releaseUnusedEquip 0 \
    -profile ptse1-bsd2 -noreserve 0 -noreplace 0 \
    -comment {<a      href="/testrunscheduler/schedulerJob.rvt?job_id=1618252">Profile Push:     1618252</a>} \
    -attr {} -dur 300minutes -controlAssert 0 -roleSubst {} -offline false -nodb 0 \
    -image {} -layer2Mode mapping -checkLeaks 0 -config {} -trace 0 -debug 0 -desc 0 \
    -notify 0 -forceProfileIP false -clusterHashingMode simple -doConfig true \
    -reservation 0 -projects pts_7_20-latest -flavor {} -platformMix {} \
    -releaseReservation 0 -pkgExt {} -emails {} -loadBalancingMode none -enableIOM false \
    -checkConn 1 -platform ptsvpl-esxi-lnx -pkgView {} -offlineFailedConn 1 -noall 0 \
    -ipMode ipv4 -runType pmgr-run -enableUdpPrioritization false \
    -params {profilemgr:profileToPush "ptse1-bsd2"  profilemgr:platform "ptsvpl-esxi-lnx"} \
    -swtc_view /m/vmurshilly_lab \
    {<br>Invocation with all defaults removed => tcl profilemgr -profile "ptse1-bsd2" -comment "<a  href="/testrunscheduler/schedulerJob.rvt?job_id=1618252">Profile Push: 1618252</a>" -dur "300minutes" -projects "pts_7_20-latest" -platform "ptsvpl-esxi-lnx" -offlineFailedConn "1"}

I tried using regexp itself which failed :

~$tcl
% regexp -all .*job_id=(.*)\"> "supercalafrajilistic" match jobID
0
% puts $jobID
can't read "jobID": no such variable
while evaluating {puts $jobID}
Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
vinay
  • 53
  • 1
  • 8
  • 2
    The usual idiom is to do the match in the condition expression of an if command. When the condition is true, the variable jobID exists; when false, it doesn't. (The 0 you get from the regexp command indicates that the match failed.) – Peter Lewerin Nov 13 '16 at 03:47
  • I've added some backslash-newlines into that string. _They're not really in your data,_ but they make it at least possible folks to read it! – Donal Fellows Nov 13 '16 at 21:30

1 Answers1

0

Well, you aren't running the regular expression against the string that you fetched but rather just the dummy “supercalafrajilistic” data; that matters quite a bit. You also need to run the regular expression in non-greedy mode, but by doing that we can simplify things quite a bit. Finally, you should check the result of regexp; in the mode you're using, it returns the number of times that the regular expression matched, which is effectively a boolean test for if something was found.

set invoc [[$this cget -testrun] cget -invocation]
if {[regexp -all {job_id=(.*?)\"} $invoc -> jobID]} {
    puts "the job ID is $jobID; yippee"
} else {
    # Up to you how to recover from this failure case...
    puts "warning: no job ID found"
}

Apart from that, it's the usual things with REs in Tcl (put your regular expressions in braces unless you know you shouldn't, use -> instead of match if you don't care about the overall match string for readability, etc.)

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
  • but problem is i do not get the same job id every time for different string: i get the result as below: % puts $jobID 1619243&project=vin_trs_debug&test_group=new_test_group_vin&platform=ptsvpl-esxi-lnx need regexp which will fetch job id from any huge string, regexp shoud limit to "job_id =1654533" and fetch only nuber 1654533 from whole huge string @Donal Fellows – vinay Nov 15 '16 at 09:12