创建一个正则表达式来找到一个括号的缩写(VBasic Word) [英] Creating a RegEx to find a sentence with a parenthetical acronym (VBasic Word)

查看:218
本文介绍了创建一个正则表达式来找到一个括号的缩写(VBasic Word)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个脚本来擦洗文档,以格式(USA)来查找缩略词。作为一个处理工具,我需要抓住括号中出现的整个句子。现在我的代码是找到它的缩写:
$ b $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $。 AZ] {2,} \)
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = True
.MatchWildcards = True

将此与Do While .Execute合并,可以梳理文档并找到缩写,然后使用字符串函数我从括号中取出缩写并放在一个表中。有没有一个正则表达式,我可以用它会发现任何一个(美国)类型的首字母缩写词是在?作为一个输入你可以使用这个段落。

非常感谢。



编辑:我找到以下正则表达式来尝试并使其工作:

$ $ $ $ $ $ $ $ c $ .Text =[^。] * \([AZ] {2, } \)[^。] * \。

但是这给我一个错误,说胡萝卜不能在Find函数中使用。

解决方案

这个正则表达式

  [^ 046] [!^ 046] * \([AZ] {2,10} \)[!^ 046] * [^ 046] 
Find 对话框中使用时,p $ p>

将会找到一个句子(以句号#046为界)。注意,这个正则表达式在两端都返回一个完全停止的字符串,例如,



。这个字母的首字母缩写(TLA)被使用了。

另外请注意,我将首字母缩写的长度限制为10个字符[AZ] {2, 10};根据需要更改上限。



最后,我观察到,这不会在句子末尾找到缩略词,例如


我用了一个三个字母的缩写(TLA)。

正则表达式的 [!^ 046] * 部分似乎不匹配长度为零的字符串。要捕捉这些情况,您需要使用以下方法进行第二次搜索:

  [^ 046] [!^ 046] * \([AZ] {2,10} \)[^ 046] 


I'm writing a script that scrubs a document to find acronyms in the format (USA). As a processing tool I need to grab the entire sentence in which that parenthetical acronym appears. Right now my code for finding the acronym is:

With oRange.Find
        .Text = "\([A-Z]{2,}\)"
        .Forward = True
        .Wrap = wdFindStop
        .Format = False
        .MatchCase = True
        .MatchWildcards = True

Combining this with a Do While .Execute I can comb the doc and find the acronyms, then using a string function I take the acronym out of the parentheses and put it in a table. Is there a RegEx that I could use which would find any sentence an (USA) type acronym is in? As an input you could use this paragraph.

Thank you very much.

edit: I found the following Regex to try and make it work:

.Text = "[^.]*\([A-Z]{2,}\)[^.]*\."

But this is giving me an error, saying that the carrot can't be used in the Find function.

解决方案

This regex

[^046][!^046]*\([A-Z]{2,10}\)[!^046]*[^046]

when used in the Find dialog will find a sentence (bounded by full stops ^046).

Note that this regex returns a string with full stops on both ends, e.g.,

. A three-letter acronym (TLA) was used.

Also note that I limited acronym length to 10 chars [A-Z]{2,10}; change the upper limit as needed.

Finally I observed that this DOES NOT find acronyms at the end of a sentence, e.g.

I used a three-letter acronym (TLA).

The [!^046]* part of the regex does not appear to match a zero length string. To catch those cases you would need to do a second pass search with this:

[^046][!^046]*\([A-Z]{2,10}\)[^046]

Hope that helps

这篇关于创建一个正则表达式来找到一个括号的缩写(VBasic Word)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆