REM ***** BASIC *****
' Crashes on second access of regex matches (line 19) without VBA support option.
Private Function RegEx_Matches_Calc_Crash()
Dim regEx As Object
Set regEx = CreateObject("VBScript.RegExp")
regEx.Global = True
regEx.IgnoreCase = True
html = "<span>10:35 AM EDT</span>"
regEx.Pattern = "<span>([0-9]{2}):([0-9]{2}) (AM|PM) (EST|EDT)</span>"
Set Matches = regEx.Execute(html)
If Matches.Count > 0 Then
TimeHour = Matches.Item(0).SubMatches.Item(0)
TimeHour = Matches.Item(0).SubMatches.Item(0)
TimeMinute = Matches.Item(0).SubMatches.Item(1)
TimeAMPM = Matches.Item(0).SubMatches.Item(2)
TimeTZ = Matches.Item(0).SubMatches.Item(3)
End If
End Function
' Version: 7.6.6.3 (X86_64) / LibreOffice Community
' Build ID: d97b2716a9a4a2ce1391dee1765565ea469b0ae7
' CPU threads: 8; OS: Windows 10.0 Build 22631; UI render: Skia/Raster; VCL: win
' Locale: en-US (en_US); UI: en-US
' Calc: threaded
Excuse me, but why CreateObject("VBScript.RegExp")
and not CreateUnoService("com.sun.star.util.TextSearch")
?
Well, for example, the .TextSearch
works without failures or crashes. And it also works on any operating system.
… python would also work on any OS
import re
html = "<span>10:35 AM EDT</span>"
rex = re.compile("<span>([0-9]{2}):([0-9]{2}) (AM|PM) (EST|EDT)</span>")
timestamp = rex.search(html)
hour, minute, A_P, zone = timestamp.groups()
Python comes with a default RegEx module (“re”) and there seems to be also an extended module.
The implementations and the features will differ in “flavor” from the RegEx engine by ICU wich is used in LibreOffice for F&R, for the TextSearch service, and for the REGEX() function.
Working with two or more different implementations within a single application could cause confusion.