1

我有一个词汇表,其中的条目以粗体文本给出,解释性文本是常规字体。我想做的是在每个粗体文本字符串之后添加一个逗号(星号或任何其他标点符号),这将使我能够将词汇表转换为 Excel 中的逗号分隔文本。有没有办法在 Word 的查找和替换对话框中使用正则表达式来做到这一点,所以我可以在词汇表中的条目的单词或短语的末尾得到一个逗号。以下是词汇表中的一个条目作为示例:

在生效时废除 ......常规字体条目的内容......

该条目是粗体短语,与之相关的解释以常规文本给出。

在尝试了表达式<[A-Za-z\,.-)(/\?! ]{1,}> Jerry 在查找框中建议和^&,在 MS Word 中的替换框中,我得到了想要的结果对于后跟分节符的粗体短语,例如标题和标题:


http://img811.imageshack.us/img811/6338/frontpagep.jpg


但是词汇表条目不会发生任何变化,因为它们后面是条目的内容,后面没有分节符。这是词汇表中的一个示例,显示了词汇表条目的特征布局:


http://img571.imageshack.us/img571/6558/samplefromtheglossary.jpg


4

3 回答 3

0

Some simple searching around shows the following documents that apply to older versions of Word- up to 2002 at least.

office support document

Note that Word's implementation of Regex is not very conformant to other people's implementations.

I didn't see a doc for a more recent version of Word. The Search and Replace in Visual Studio (I think this works in the free version too), or in an IDE like Eclipse, does support Regex, so you have lots of non-Word options that might work as well.

于 2013-04-11T16:45:54.380 回答
0

使用通配符,将格式字体设置为粗体。对于搜索,输入<*>。对于替换,输入^&,图片值一千个剧本

于 2013-04-11T16:44:54.267 回答
0

你可以试试这个:

<[A-Za-z\,\.\-\)\(\/\?\! ]{1,}>

而不是之前建议的发现<*>乔治?

在新的 OP 编辑​​之后:

您可以尝试将其放入宏中:

Sub CommaAdder()
    Selection.Find.ClearFormatting
    Selection.Find.Font.Bold = True
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "<[A-Za-z]@>"
        .Replacement.Text = "^&,"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchFuzzy = False
        .MatchWildcards = True
    Selection.Find.Execute Replace:=wdReplaceAll
    End With
    With Selection.Find
        .Text = ",([\)])"
        .Replacement.Text = "\1,"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchFuzzy = False
        .MatchWildcards = True
    Selection.Find.Execute Replace:=wdReplaceAll
    End With
    With Selection.Find
        .Text = ",([\-\?\/\!\.\, ])"
        .Replacement.Text = "\1"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchFuzzy = False
        .MatchWildcards = True
    Selection.Find.Execute Replace:=wdReplaceAll
    End With
    With Selection.Find
        .Text = "([A-Za-z]@ )"
        .Replacement.Text = "\1,"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchFuzzy = False
        .MatchWildcards = True
    Selection.Find.Execute Replace:=wdReplaceAll
    End With
    With Selection.Find
        .Text = "( \,)([A-Za-z]@)"
        .Replacement.Text = ", \2"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchFuzzy = False
        .MatchWildcards = True
    Selection.Find.Execute Replace:=wdReplaceAll
    End With
    With Selection.Find
        .Text = "\,\("
        .Replacement.Text = "("
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchFuzzy = False
        .MatchWildcards = True
    Selection.Find.Execute Replace:=wdReplaceAll
    End With
    With Selection.Find
        .Text = "\, "
        .Replacement.Text = " "
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchFuzzy = False
        .MatchWildcards = True
    Selection.Find.Execute Replace:=wdReplaceAll
    End With
    With Selection.Find
        .Text = " \,"
        .Replacement.Text = ", "
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchFuzzy = False
        .MatchWildcards = True
    Selection.Find.Execute Replace:=wdReplaceAll
    End With
End Sub

我不知道如何编写宏,但我记录了一个替换来构建它,如果你明白一点,有 3 个替换一个接一个地进行。第一个查找所有粗体单词并在它们之间放置一个逗号,即使有)or.等​​。第二个专门查找我刚刚提到的删除该逗号的实例,以及我们有一个逗号后跟一个粗体的实例white space ,,除了,)在最后一个替换中解决的部分之外,它用代替替换它),

问题是,如果你有类似的东西:

这是大胆的,但不是这个

bold之间的空白but也具有bold格式,它将在第二次替换时被删除。如果有一种方法可以找到部分粗体和部分非粗体的文本,那么就不会有任何问题。我正在尝试寻找解决方案,但如果此代码有任何问题,请告诉我。如果没有像这样粗体格式的空格,就不会有任何问题!

重新编辑:这现在也适用于粗体空间!虽然不是很整齐...

于 2013-04-11T17:14:09.343 回答