Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Does RegularExpression() work?

May
12,846
164
I can't get a simple example to work. This code produces the result below it.
Code:
    LPBYTE pMatchStart, pMatchEnd;
    UINT uRegions = 0; // also tried 1 with the same result
    WCHAR szString[32] = L"Hello world";
    WCHAR pRegex[32] = L"ello";
    Printf(L"RegularExpression() = %d\r\n",
        RegularExpression(pRegex, (LPBYTE) szString, &pMatchStart, &pMatchEnd, &uRegions, 0, 1, 1));
    Printf(L"Data: %X %X %X %u\r\n", szString, pMatchStart, pMatchEnd, uRegions);

Code:
RegularExpression() = 0
Data: 1717C60 0 0 0
 
Your syntax is incorrect; you have to set the pMatchStart to the beginning of the text to search, and pMatchEnd to the end of the text.
And then what ... test that uRegions > 0? And if so, will pMatchStart and pMatchEnd have been updated to be the boundaries of the matching text?
 
Why are you trying to use this function instead of calling Oniguruma yourself (like you always have in the past)? The function format will definitely change from version to version.
In fact I am doing it myself (see below for my RegExp() which returns a pointer to a match and fills in a length parameter). But I had thought that you supplied RegularExpression() for the benefit of plugin authors.
Code:
#define INVALID_LPWSTR ((LPWSTR) (LONG_PTR) -1)
 
LPWSTR RegExp(LPWSTR pRegEx, LPWSTR pString, DWORD *pLen)
{
    OnigErrorInfo err_info;
 
    WCHAR *rv = NULL;
    OnigRegex regex;
    INT ec = onig_new(&regex, (UChar*) pRegEx, (UChar*) pRegEx + 2 * lstrlen(pRegEx),
        0, ONIG_ENCODING_UTF16_LE, g.pOnigSyntax, &err_info);
    if ( ec != ONIG_NORMAL )
    {
        OnigErrorMessage(ec);
        return INVALID_LPWSTR;
    }
 
    UChar *mstart = (UChar*) pString, *mend = (UChar*) pString + 2 * lstrlen(pString);
 
    OnigRegion *region = onig_region_new();
 
    if ( onig_search(regex, mstart, mend, mstart, mend, region, 0) >= 0 )
    {
        *pLen = (region->end[0] - region->beg[0]) / sizeof(WCHAR);
        rv = pString + region->beg[0] / sizeof(WCHAR);
    }
    onig_region_free(region, 1);
    onig_free(regex);
    return rv;
}
 
In fact I am doing it myself (see below for my RegExp() which returns a pointer to a match and fills in a length parameter). But I had thought that you supplied RegularExpression() for the benefit of plugin authors.

Functions in takecmd.dll are there for the benefit of tcmd.exe and tcc.exe. A few might also be useful to plugin authors, but for 90% of them I won't promise that they'll keep the same arguments (or name). The only ones you can rely on are the internal commands and the variable parsing.
 
Back
Top