9

I have a complex VBA project which I have used for ten or fifteen years with no issues. All of sudden, today it started to crash with a non-VBA error message. I am guessing this is referring to the underlying code for the VBScript Regular Expressions 5.5 reference:

MSVCR error dialog: Assertion failed

Microsoft Visual C++ Runtime Library

Assertion failed!

Program: ...
File: g:\vba\src\65_VC8\VBA\rt\regexpbase.cxx
Line: 2063

Expression: ibLim == m_ibMin

For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts

(Press Retry to debug the application - JIT must be enabled)

[Abort] [Retry] [Ignore]

The following code snippet, at least on my computer, reproduces the problem (this code uses early binding, but the same error occurs using late binding):

Option Explicit
Sub due()
    Dim RE As RegExp
    
Const sPATepi As String = "(?!.*sample)\\([^\\]+)\\(S\d\d(?:E\d{2,3}(?:-E?\d{2,3})?)+)\\(.*)(?=\.(?:mkv|avi|mp4|wmv)$)"
Const Test As String = "\\DS718\Video\TV Shows\Death in Paradise\S14E08\Episode 8 720p HDTV.mkv"

Set RE = New RegExp
With RE
    .Global = True
    .IgnoreCase = True
    .Pattern = sPATepi
    .Multiline = True
End With

'Crashes if result = True
Debug.Print RE.Test(Test)

End Sub

RE.Test(test) in the above code evaluates to True in a regex tester (as it has on this program for years).

Simpler regular expressions do not have this problem. (eg. pattern = "\d+" will evaluate to True and not crash).

I really don't know where to go with debugging this further. I have run DISM with no errors found.

22
  • 1
    @sln Both the regex and the test string are fed to the regex engine exactly as shown in the code (minus the leading and trailing double quote marks). In the vbscript regex engine, the escaping is necessary to properly match the `\`s seen in the target. And the regex has matched that particular target almost daily for the past five months with no errors. Commented Sep 8 at 23:21
  • 1
    @sln In VBA, using debug.print for the pattern, and also for the target was how I constructed the test vba macro. Also, using both the pattern and the target in regex buddy shows that the regex matches the part of the target it is designed to match: \Death in Paradise\S14E08\Episode 8 720p HDTV Commented Sep 8 at 23:33
  • 3
    In the Office update (ver.2508) , when we use Replace Function or Lookahead (?=) or NegativeLookahead (?!) suddenly encount an error. Commented Sep 9 at 8:53
  • 3
    Many thanks to @user31450453 for pointing out the problem with lookaheads in Office update 2508. Removing the lookaheads in my regex cured the problem I posted. I sure hope MS fixes this soon, though. Commented Sep 9 at 12:21
  • 3
    Upon advice on another forum, the following works even with the lookahead :Dim RE As New RegExp: Set RE = GetObject("", "VBScript.RegExp"). Why GetObject works and CreateObject or the original code don't work is not clear. Perhaps now that the REGEX engine is built into VBA, GetObject is picking up that code rather than the .dll Commented Sep 9 at 18:25

2 Answers 2

10

As of Microsoft® Excel® for Microsoft 365 MSO (Version 2509 Build 16.0.19231.20138) 64-bit (Current Channel Click-to-Run) the bug seems to have been repaired.


I hesitate to post this answer because, even though it works, I'm not sure why it works nor how long it may continue to work in the future.

The problem seems to have arrived with the latest office update (2508) and has been widely reported.

And I would like to thank all of the commenters for their useful and relevant comments, as well as for confirming that this is an issue that has cropped up in multiple environments.

Not sure if this is related, but I note that in VBA, setting of a reference to Microsoft VBScript Regular Expressions 5.5 is no longer necessary.

But it seems as if initiating the regex engine differently restores the functionality of the lookahead both positive and negative.

I obtained this suggestion from another thread on a Microsoft forum in the answer posed by Viorel (NOT the accepted answer). I get ASSERTION FAILED using VBSCRIP RegEx

Instead of declaring as

Dim oRegEx As RegExp
Set oRegEx = New RegExp

We declare as:

Dim oRegEx As RegExp
Set oRegEx = GetObject("", "VBScript.RegExp")

Why this works is unclear to me.

Sign up to request clarification or add additional context in comments.

10 Comments

It seems the New keyword is not necessary to initiate the Regex engine. So I have eliminated it from the code.
There is a deleted answer by user qinliuMSFT (who apears to be a MS employee) that states in part Thank you for reporting this issue! We’ve identified it and are currently working on a fix. (I'm posting this as a comment so <10k users can see it's acknowledged as a bug. Shame on the deleters for removing useful content)
You may be able to vote to undelete it.
Having an xlsb file I was unable to edit the macro, another temporary fix is to revert to a functioning version of Office 365. Using the instructions here I reverted to the latest 2507 version (19029.20208) and all works well.
can you please share your used .xml code? Also try to downgrade but it did work
I copy and pasted the code from the reference, using the most recent 2507 version: <Configuration> <Updates Enabled="TRUE" TargetVersion="16.0.19029.20208" /> </Configuration> Don't forget to disable the automatic updates.
Have try exact that config for xml but I get the 2508 Version installed :-( Try to deinstall before but same effect. Maybe you have another tip?
Is your 365 Click-to-Run or something else (eg msi). The process in the link will only work for Click-to-Run. Are Automatic Updates disabled? Is Config.xml in the same folder as setup.exe and is it named exactly Config.xml?
Were any of my last comments applicable?
As of Microsoft® Excel® for Microsoft 365 MSO (Version 2509 Build 16.0.19231.20138) 64-bit (Current Channel Click-to-Run) the bug seems to have been repaired.
0

Yes, there are new bugs in the new library:
When defining a LOOKAHEAD, the library CRASHES as soon as a match is found: Here: (?=§).
I want to find several items delimited between §....§, starting with a date, in a match collection, therefore the lookahead, otherwise the closing § is "eaten" and the next match not found.

That one worked before and now crashes.

Sub CrashTest3()
    Dim R As RegExp
    Dim txt As String
    Set R = new RegExp
    R.Pattern = "§\D{0,4}(\d{4}\-\d{2}\-\d{2}[^\s]*?)\s+(.*?)(?=§)"
    txt = "§AAA§BBB§CCC§2024-07-14 DDD§"
    Debug.Print R.Test(txt)
End Sub

The following works, but misses the second item, e.g. §2025-09-01 XXXX§2025-06-09 YYYY§, therefore the lookahead:

§\D{0,4}(\d{4}\-\d{2}\-\d{2}[^\s]*?)\s+(.*?)§

Useless to say that the library still doesn's support lookbehind or UTF8
When will Microsoft give us a DECENT Regex implementation in VBA ??
It would be so easy, because it is there in .net.
But even trying to create our own COM library is now blocked - can't be registered.

UPDATE:
I can confirm that the update is available and works.
Version 2509 Build 16.0.19231.20044) 64-bit
Had to request it manually though (File - Update Options - Update Now)
The following minimal crashtest for lookahead should output: True and 2


Sub crashtest4()
    Dim txt As String: txt = "§A§B§"
    With New RegExp
        .Pattern = "§([^§]*?)(?=§)"
        .Global = True
        Debug.Print .Test(txt)
        With .Execute(txt)
            Debug.Print .Count
        End With
    End With
End Sub

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.