OpenOffice.org:Regex-跳过第一场比赛

时间:2014-06-12 00:22:14

标签: regex openoffice.org

我在OpenOffice.org calc文档中有一些格式错误的电话号码,我想修复它。 错误格式的看起来像这样:

555 / 28 / 2910 / 187 / 1

他们应该如何看待:

555 / 2829101871

我现在的问题是:如何删除单元格中的每个斜杠但是留下第一个斜杠?

2 个答案:

答案 0 :(得分:2)

这将选择粗体部分:555 /( 28/2910/1887/1 ):

[^\/]+\/ (.*)

Live Demo

如果您只想选择右侧空格三个斜杠:555/28(/)2910(/)187(/)1 < / p>

[^\/]+\/ [^\/]+( \/ )[^\/]+( \/ )[^\/]+( \/ )

<强> Live Demo

答案 1 :(得分:0)

VBAScript不支持lookbehind。也不是,据我所知,它是否支持替换回调,否则我们可以使用此问题中的方法"regex-match a pattern unless..."来执行以下操作:

Dim myRegExp, replaced
Set myRegExp = New RegExp
myRegExp.Global = True
myRegExp.Pattern = "^[^ /]* / |( / )"
replaced = myRegExp.Replace(SubjectString, 
     // some function that only replaces the match if Group 1 is set.
                            )

据我所知,这给我们留下了三步解决方案:

  1. 用独特的
  2. 替换第一个
  3. 替换其他
  4. 再次更换第一个
  5. <强> 1。替换第一个:

    搜索:^([^ /]*) /

    替换:$1@@DISTINCTIVE@@

    一些代码:

    Dim myRegExp, replaced
    Set myRegExp = New RegExp
    myRegExp.Global = True
    myRegExp.Pattern = "^([^ /]*) / "
    replaced = myRegExp.Replace(SubjectString, "$1@@DISTINCTIVE@@")
    

    <强> 2。替换其他的:

    搜索:/,替换:""

    第3。恢复第一个:

    搜索:@@DISTINCTIVE@@,替换:/