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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.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 Excel正则表达式添加2个空格,而不是1个_Regex_Excel_Vba - Fatal编程技术网

Regex Excel正则表达式添加2个空格,而不是1个

Regex Excel正则表达式添加2个空格,而不是1个,regex,excel,vba,Regex,Excel,Vba,我正在使用Excel中的以下函数拆分某些数据的上限。我如何调整它以在单词之间添加两个空格,例如Mike Jones,而不是像现在这样只添加一个空格。我相信答案很简单,但即使在最好的时候,正则表达式也让我感到困惑 Function SplitCaps(strIn As String) As String Dim objRegex As Object Set objRegex = CreateObject("vbscript.regexp") With objRegex .Global =

我正在使用Excel中的以下函数拆分某些数据的上限。我如何调整它以在单词之间添加两个空格,例如
Mike Jones
,而不是像现在这样只添加一个空格。我相信答案很简单,但即使在最好的时候,正则表达式也让我感到困惑

Function SplitCaps(strIn As String) As String
Dim objRegex As Object
Set objRegex = CreateObject("vbscript.regexp")
With objRegex
    .Global = True
    .Pattern = "([a-z])([A-Z])"
    SplitCaps = .Replace(strIn, "$1 $2")
End With
End Function

非常非常简单:在2个正则表达式组$1和$2之间添加额外的空间

SplitCaps = .Replace(strIn, "$1  $2")

我想你只需要

    ([a-zA-Z]*\s*[a-zA-Z]*)*

您是否尝试添加“\s”?这应该是一个评论,但我现在不能评论。 尝试: 您可以使用\s添加额外的空白:

    SplitCaps = .Replace(strIn, "$1\s\s$2")