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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.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 正则表达式捕获1个字符_R_Regex - Fatal编程技术网

R 正则表达式捕获1个字符

R 正则表达式捕获1个字符,r,regex,R,Regex,只要存在长度为1的英文字符,我希望它与前面的文本相结合 gsub('(.*)\\s+([a-zA-Z]{1})', "\\1\\2", 'Anti-Candida a ингибинов') Anti-Candidaa ингибинов 对于下面的示例,它应该返回'Anti-Candida amцццццццццццццццц gsub('(.*)\\s+([a-zA-Z]{1})', "\\1\\2", 'Anti-Candida am ингибинов') 您可以使用此正则表达式:

只要存在长度为1的英文字符,我希望它与前面的文本相结合

gsub('(.*)\\s+([a-zA-Z]{1})', "\\1\\2", 'Anti-Candida a ингибинов')

Anti-Candidaa ингибинов
对于下面的示例,它应该返回
'Anti-Candida amцццццццццццццццц

gsub('(.*)\\s+([a-zA-Z]{1})', "\\1\\2", 'Anti-Candida am ингибинов')

您可以使用此正则表达式:

\W+([a-zA-Z])\b
替换为
\\1
。这里的技巧是在单个字母后匹配单词边界

如果您只是在末尾添加
\b
,您的正则表达式也可以工作