在R中,我需要想出一种从以下数据中提取的方法:
Using Notifications API: Strategy ON_TARGET:LookForward Ratio: 0.25 Num of hours back: 6 Rpr Cfg--> FP: 9.02 CP: 18.04 MSR: 0.51 MPR: 0.49 TTRR: 0.51. RepricingMethod_ReachTopRankOnTarget: Sampling info: Dilutions: 2_1_1_7_4_2-AKQSGIBQINE7B, 1_1_1_3_4_2-A2TBTG410J2ORU, 1_1_1_5_4_2-AQNACJEM8PUJ1, 1_1_1_6_4_2-A2R0FX412W1BDT, 1_1_1_6_4_2-A1TFBK3C7LO58P, 1_1_1_4_4_2-A1WMYU489BEYM4, 1_1_1_7_3_2-A3G2RBEZBLAJ53, 1_1_1_5_4_2-A2RFSIF56F6W5J, 1_1_1_6_4_2-AAL7E530K3IX2, 1_1_1_7_4_2-AFAGM2K2OIRAD, 1_1_1_6_4_2-APRB74G8QOR1X, 1_1_1_5_3_2-A24POLY6RKLSW7, 1_1_1_5_4_2-A18IJX3G7FD5MC, 1_1_1_5_3_2-A1UEW3GW612BDQ, 1_1_1_7_4_2-A2G88111572J8M, 1_1_1_4_4_2-A2IKHPELK48TV7, 1_1_1_7_4_2-A79CLRHOQ3NF4, Additions: None.New TTR: 0.9 Merchant is not top ranked, merchant group known (2_1_1_7_4_2-AKQSGIBQINE7B), top ranked group known (2_1_1_7_4_2-ATVPDKIKX0DER), taking prices of 1 groups above/equal merchant group as reference. Lowest landing price within these groups is 9.19 . Initially suggested change: 0.0, change determined upon historical analysis: 0.0 with significance of 1.0, prediction for top rank: false, state trace: -_S6_S8- HWP: null- LLP: 9.02 Reducing price obtained by history to 8.91. Modification: New price lower than floor price, reset to floor price. Target optimization: Current top rank ratio is 0.0, different optimal ratio was not found.
模式后出现的数值' TTRR:'并以点(。)结束。在上面的示例中,返回的值应为0.51。 有什么想法吗?
答案 0 :(得分:0)
您可以尝试下面的正则表达式。
"TTRR:\\s*\\K\\d+(?:\\.\\d+)?(?=\\.)"
\K使文本与整个正则表达式匹配保持匹配。
> x <- "Using Notifications API: Strategy ON_TARGET:LookForward Ratio: 0.25 Num of hours back: 6 Rpr Cfg--> FP: 9.02 CP: 18.04 MSR: 0.51 MPR: 0.49 TTRR: 0.51. RepricingMethod_ReachTopRankOnTarget: Sampling info: Dilutions: 2_1_1_7_4_2-AKQSGIBQINE7B, 1_1_1_3_4_2-A2TBTG410J2ORU, 1_1_1_5_4_2-AQNACJEM8PUJ1, 1_1_1_6_4_2-A2R0FX412W1BDT, 1_1_1_6_4_2-A1TFBK3C7LO58P, 1_1_1_4_4_2-A1WMYU489BEYM4, 1_1_1_7_3_2-A3G2RBEZBLAJ53, 1_1_1_5_4_2-A2RFSIF56F6W5J, 1_1_1_6_4_2-AAL7E530K3IX2, 1_1_1_7_4_2-AFAGM2K2OIRAD, 1_1_1_6_4_2-APRB74G8QOR1X, 1_1_1_5_3_2-A24POLY6RKLSW7, 1_1_1_5_4_2-A18IJX3G7FD5MC, 1_1_1_5_3_2-A1UEW3GW612BDQ, 1_1_1_7_4_2-A2G88111572J8M, 1_1_1_4_4_2-A2IKHPELK48TV7, 1_1_1_7_4_2-A79CLRHOQ3NF4, Additions: None.New TTR: 0.9 Merchant is not top ranked, merchant group known (2_1_1_7_4_2-AKQSGIBQINE7B), top ranked group known (2_1_1_7_4_2-ATVPDKIKX0DER), taking prices of 1 groups above/equal merchant group as reference. Lowest landing price within these groups is 9.19 . Initially suggested change: 0.0, change determined upon historical analysis: 0.0 with significance of 1.0, prediction for top rank: false, state trace: -_S6_S8- HWP: null- LLP: 9.02 Reducing price obtained by history to 8.91. Modification: New price lower than floor price, reset to floor price. Target optimization: Current top rank ratio is 0.0, different optimal ratio was not found."
> m <- gregexpr("TTRR:\\s*\\K\\d+(?:\\.\\d+)?(?=\\.)", x, perl=TRUE)
> regmatches(x, m)
[[1]]
[1] "0.51"
或强>
> gsub("TTRR:\\s*(\\d+(?:\\.\\d+))|.", "\\1", x)
[1] "0.51"
> gsub("TTRR:\\s*(\\d+(?:\\.\\d+))\\.|.", "\\1", x)
[1] "0.51"
答案 1 :(得分:0)
您可以在此处使用基本替换。
sub('.*TTRR:\\s*([0-9.]+)\\..*', '\\1', x)
# [1] "0.51"