Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex R:Can';t使用lookahead或lookahead strsplit正确拆分字符串_Regex_R - Fatal编程技术网

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"