Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.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
R:gsub保留字符串中字符之间的空格而不删除_R_Regex_Gsub - Fatal编程技术网

R:gsub保留字符串中字符之间的空格而不删除

R:gsub保留字符串中字符之间的空格而不删除,r,regex,gsub,R,Regex,Gsub,我有一个字符串,它们之间有数字字符 TestString = "white tiger roars.12.03.001-fast horse runs13.15.01.001-cat is useless 11.01.09.001-dog barks22.07.01.001" 我不想让它看起来像 "white tiger roars-fast horse runs-cat is useless-dog barks" 到目前为止,我无法保留字里行间的空隙 gsub("[^a-z-]", "",

我有一个字符串,它们之间有数字字符

TestString = "white tiger roars.12.03.001-fast horse runs13.15.01.001-cat is useless 11.01.09.001-dog barks22.07.01.001"
我不想让它看起来像

"white tiger roars-fast horse runs-cat is useless-dog barks"
到目前为止,我无法保留字里行间的空隙

gsub("[^a-z-]", "", TestString) 
#"whitetigerroars-fasthorseruns-catisuseless-dogbarks"

只需添加一个空格?[^a-z-]或gsub\\d*[.]*,TestStrings这太简单了。感谢这将导致无用的狗吠在最后,这是不同于预期的结果。
gsub("\\s?(\\d+|\\.)","","white tiger roars.12.03.001-fast horse runs13.15.01.001-cat is useless 11.01.09.001-dog barks22.07.01.001")
[1] "white tiger roars-fast horse runs-cat is useless-dog barks"