gpt4 book ai didi

regex - VBscript_Words 仅包含唯一且不区分大小写的字母

转载 作者:行者123 更新时间:2023-12-01 12:18:17 25 4
gpt4 key购买 nike

我有一个很大的文本文件,我需要在其中找到只包含唯一字母(a-zA-Z)的单词。单词不应包含字母以外的任何字符。此外,它需要不区分大小写,以便不匹配 alphAmorNing 等词。

例子:

 marco        -  Should match(because of unique letters)
asia - Should Not Match(contains 2 'a')
asiA - Should Not Match(as it has 'a' and 'A')
alpha - Should not match
mike - Should match
roger - Should not match
abascus - Should not match
mach1 - Should not match(because of presence of 1)

我需要测试的文件中的示例文本:

The shares together form stock.The stock of a corporation is partitioned into shares, the total of which are stated at the time of business formation. Additional shares may subsequently be authorized by the existing shareholders and issued by the company. In some jurisdictions, each share of stock has a certain declared par value, which is a nominal accounting value used to represent the equity on the balance sheet of the corporation. In other jurisdictions, however, shares of stock may be issued without associated par value.

Shares represent a fraction of ownership in a business. A business may declare different types (or classes) of shares, each having distinctive ownership rules, privileges, or share values. Ownership of shares may be documented by issuance of a stock certificate. A stock certificate is a legal document that specifies the number of shares owned by the shareholder, and other specifics of the shares, such as the par value, if any, or the class of the shares.

In the United Kingdom, Republic of Ireland, South Africa, and Australia, stock can also refer to completely different financial instruments such as government bonds or, less commonly, to all kinds of marketable securities.

我的尝试:

\b(?![^a-zA-Z]+)(?!(?:[a-zA-Z]*([a-zA-Z]))*\1)[ a-zA-Z]+\b

但它是not able to match anything here .

我被困在这里已经有一段时间了。请指出我正确的方向。谢谢

最佳答案

试试这个正则表达式:

\b(?![^a-zA-Z]+\b)(?![a-zA-Z]*([a-zA-Z])[a-zA-Z] *\1)[a-zA-Z]+\b

Click for Demo

解释:

  • \b - 单词边界
  • (?![^a-zA-Z]+\b) - 否定前瞻验证单词应该只包含 1+ 个字母
  • (?![a-zA-Z]*([a-zA-Z])[a-zA-Z]*\1) - 另一个负面前瞻 - 这部分用于验证没有重复 2 个字母。下面进一步分解:
    • [a-zA-Z]* - 检查是否存在 0+ 个字母
    • ([a-zA-Z]) - 捕获一组中的字母。将检查组中捕获的这封信是否有重复。
    • [a-zA-Z]* - 再次检查是否存在 0+ 个字母,以考虑重复字母彼此不相邻的情况。
    • \1 - 检查在 group1 中捕获的字母
  • [a-zA-Z]+ - 匹配出现 1 次以上的字母
  • \b - 字边界

VBScript 代码:

Option Explicit
Dim objRE, strTest, objMatches, match, strOutput
strTest = "marco asia asiA alpha mike roger abascus mach1"
Set objRE = New RegExp
objRE.Global=True
objRE.IgnoreCase=True
objRE.Pattern="\b(?![^a-zA-Z]+\b)(?![a-zA-Z]*([a-zA-Z])[a-zA-Z]*\1)[a-zA-Z]+\b"
Set objMatches = objRE.Execute(strTest)
For Each match In objMatches
strOutput = strOutput & match.Value & vbCrLf
Next
MsgBox strOutput
Set objMatches = Nothing
Set objRE = Nothing

输出:

enter image description here

关于regex - VBscript_Words 仅包含唯一且不区分大小写的字母,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46512397/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com