Regex R:Can';t使用lookahead或lookahead strsplit正确拆分字符串
这是绳子Regex R:Can';t使用lookahead或lookahead strsplit正确拆分字符串,regex,r,Regex,R,这是绳子 15 3 23 11 0 51.0000000 0 18G 5G 7G 9G10G13G16G19G20G27G28G30R 2 我需要用“G”和“R”来分开 我正在尝试使用“向前看”和“向后看” Lookbehindss.tl.pattern=“(?我们可以使用strsplit strsplit(str1, "(?<=\\d)(?=(G|R))", perl=TRUE)[[1]] #[1] "15 3 23 11 0 51.0000000 0 18" "G 5"
15 3 23 11 0 51.0000000 0 18G 5G 7G 9G10G13G16G19G20G27G28G30R 2
我需要用“G”和“R”来分开
我正在尝试使用“向前看”和“向后看”
Lookbehind
ss.tl.pattern=“(?我们可以使用strsplit
strsplit(str1, "(?<=\\d)(?=(G|R))", perl=TRUE)[[1]]
#[1] "15 3 23 11 0 51.0000000 0 18" "G 5" "G 7" "G 9"
#[5] "G10" "G13" "G16" "G19"
#[9] "G20" "G27" "G28" "G30"
#[13] "R 2"
strsplit(str1),(?我们可以使用strsplit
strsplit(str1, "(?<=\\d)(?=(G|R))", perl=TRUE)[[1]]
#[1] "15 3 23 11 0 51.0000000 0 18" "G 5" "G 7" "G 9"
#[5] "G10" "G13" "G16" "G19"
#[9] "G20" "G27" "G28" "G30"
#[13] "R 2"
strsplit(str1),(?我可能会尝试使用regmatches
或类似的解决方法,但我仍然想知道为什么它会这样工作,您需要scan(text=gsub)()还是使用strsplit
即strsplit(str1),”(?我认为解释是。看起来像是ByDesign。我可能会尝试使用regmatches
或类似的解决方法,但我仍然想知道为什么它会这样工作。你需要scan(text=gsub(“)还是使用strsplit
即strsplit(str1)”(?我认为解释是。看起来像是ByDesign。
[[3]]
[1] " 15 3 23 11 0 20.0000000 0 18" "G"
[3] " 5" "G"
[5] " 7" "G"
[7] " 9" "G"
[9] "10" "G"
[11] "13" "G"
[13] "16" "G"
[15] "19" "G"
[17] "20" "G"
[19] "27" "G"
[21] "28" "G"
[23] "30" "R"
[25] "2"
strsplit(str1, "(?<=\\d)(?=(G|R))", perl=TRUE)[[1]]
#[1] "15 3 23 11 0 51.0000000 0 18" "G 5" "G 7" "G 9"
#[5] "G10" "G13" "G16" "G19"
#[9] "G20" "G27" "G28" "G30"
#[13] "R 2"
str1 <- "15 3 23 11 0 51.0000000 0 18G 5G 7G 9G10G13G16G19G20G27G28G30R 2"