我有一个RegEx模式
'/* declarations */
Dim r As Range, c As Range
Dim d As Object
Dim ret, i As Long
'/* create and assign dictionary object which will be used in removing duplicates */
Set d = CreateObject("Scripting.Dictionary")
'/* call Input box method type 8 which accepts Range Objects and assign to variable */
On Error Resume Next '/* Needed in case invalid or no selection was made */
Set r = Application.InputBox("Select Range", "Remove Duplicates by Row", , , , , , 8)
On Error GoTo 0 '/* reset the error handling so other errors are trapped */
If Not r Is Nothing Then '/* Test if r is assigned successfully */
For i = 0 To r.Rows.Count - 1 '/* iterate the rows of the selected range */
For Each c In r.Offset(i).Resize(1) '/* iterate per cell of that row */
'If Not d.Exists(c.Value2) Then d.Add c.Value2, c.Value2 '~> case sensitive
'/* below is a non-case sensitive comparison */
If Not d.Exists(UCase(c.Value2)) Then d.Add UCase(c.Value2), c.Value2
'/* used dictionary object method Exists to determine duplicates */
Next '/* repeat until all values on the target range is checked */
ret = d.Items() '/* assign the unique items to array */
r.Offset(i).Resize(1).ClearContents '/* clear the existing content of the target range */
r.Offset(i).Resize(1, UBound(ret) + 1) = ret '/* assign the new contenst */
d.RemoveAll '/* clear the existing items in dictionary object */
Next '/* repeat the process for the next row */
End If
如何匹配与此模式不匹配的所有字符串?
答案 0 :(得分:3)
如果你仔细研究并尝试理解这一点。逻辑上它会是这样的。假设如果有一个条件表示X
或Y
,那么对它的否定将既不是X
也不是Y
。
X or Y
negation
将等于 Neither X and Nor Y
。
为此,你可以试试这个。
正则表达式: ^(?!\d+$)(?!\w+-\d+$).*$
1。
^
字符串的开头。2。
(?!\d+$)
数字的负向预测直到字符串结尾。3。
(?!\w+-\d+$)
对words
进行负面预测,然后是-
,然后是digits
,直至结束。4.
.*$
匹配所有内容直到结束。