LibreOffice Calc Userdefine Function for Formula

I am using Ubuntu 22.04 and LibreOffice 24.8.4.2. I don’t have knowledge of any programming language. I want to create two user defined functions from following formulas. Please suggest required changes in the following.

The function ANIRUDDHA is supposed to extract First Name Vs First Name from a cell. Means if A1 cells contains the text State of Maharashtra Vs Aniruddha Purushottamrao Mohod the function will result in State Vs Aniruddha
Function ANIRUDDHA(a)
ANIRUDDHA=REGEX(C3, “((?:(?:\w+.|M/s|Mr.|Shri|Mrs.|P|PSO|Sk|P S O|P S|Md|Sau|Sd|Dr|Ms) )?\w+).* Vs ((?:(?:\w+.|M/s|Mr.|Shri|Mrs.|Sk|Md|Sau|Sd|Dr|Ms) )?\w+).*” , “$1 Vs $2” )
End Function

The function is suppose the show the difference between two dates which are not formatted as dates.
Function MOHOD(a,b)
MOHOD=DATEDIF(DATE(RIGHT(A2,4),MID(A2,4,2) ,LEFT(A2,2) ),DATE(RIGHT(B2,4),MID(B2,4,2) ,LEFT(B2,2) ),“y”) & " Years " & DATEDIF(DATE(RIGHT(A2,4),MID(A2,4,2) ,LEFT(A2,2) ),DATE(RIGHT(B2,4),MID(B2,4,2) ,LEFT(B2,2) ),“ym”) & " Months " & DATEDIF(DATE(RIGHT(A2,4),MID(A2,4,2) ,LEFT(A2,2) ),DATE(RIGHT(B2,4),MID(B2,4,2) ,LEFT(B2,2) ),“md”) & " Days"

End Function

With the help of Chat GPT the following code is working but only when it is put in Standard

Function DateDifference(startDate As String, endDate As String) As String
    Dim d1 As Date, d2 As Date
    Dim years As Integer, months As Integer, days As Integer

    ' Convert DD/MM/YYYY or similar format into a real date
    d1 = DateSerial(Right(startDate, 4), Mid(startDate, 4, 2), Left(startDate, 2))
    d2 = DateSerial(Right(endDate, 4), Mid(endDate, 4, 2), Left(endDate, 2))

    ' Calculate differences
    years = DateDiff("yyyy", d1, d2)
    months = DateDiff("m", DateAdd("yyyy", years, d1), d2)
    days = DateDiff("d", DateAdd("m", months, DateAdd("yyyy", years, d1)), d2)

    ' Format result
    DateDifference = years & " Years " & months & " Months " & days & " Days"
End Function

but the code


Function ExtractVsParties(text As String) As String
    Dim regex As Object
    Dim matches As Object
    Dim pattern As String
    Dim result As String

    ' Regular expression pattern similar to the REGEX formula
    pattern = "((?:(?:\w+\.|M/s|Mr\.|Shri|Mrs\.|P|PSO|Sk|P S O|P S|Md|Sau|Sd|Dr|Ms) )?\w+).* Vs ((?:(?:\w+\.|M/s|Mr\.|Shri|Mrs\.|Sk|Md|Sau|Sd|Dr|Ms) )?\w+).*"

    ' Create the regex engine
    Set regex = CreateObject("VBScript.RegExp")
    regex.Pattern = pattern
    regex.Global = False
    regex.IgnoreCase = True

    ' Execute regex match
    If regex.Test(text) Then
        Set matches = regex.Execute(text)
        result = matches(0).Submatches(0) & " Vs " & matches(0).Submatches(1)
    Else
        result = text ' Return original text if no match is found
    End If

    ExtractVsParties = result
End Function

is giving the error on the line
Set regex = CreateObject(“VBScript.RegExp”)

any solutions

If a user often needs FunctionAccess(), my “Code Snippet” can help.
If function access is needed frequently, it may be justified to create a module for the code from the above linked URL in “My Macros…” Standard library, and to place the global variable there in the respective module.