需要從這個巨大的字符串(1618252)中獲取作業ID並且沒有正則表達式來執行此操作,因爲它可能會失敗時作業ID是沒有找到----------tcl需要一種方法來從巨大的字符串中獲取作業ID無正則表達式使用作爲案例可能會失敗
% 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"}
我嘗試使用正則表達式本身,這失敗:
~$tcl
% regexp -all .*job_id=(.*)\"> "supercalafrajilistic" match jobID
0
% puts $jobID
can't read "jobID": no such variable
while evaluating {puts $jobID}
通常的習慣用法是在if命令的條件表達式中進行匹配。當條件爲真時,變量jobID存在;當錯誤時,它不會。 (從regexp命令中得到的0表示匹配失敗。) –
我已經在該字符串中添加了一些backslash-newlines。 _他們不是真的在你的數據中,_但他們至少讓人們可以閱讀它! –