I am compiling a PCRE template with the utf8 flag turned on and trying to match the utf8 char*
string to it, but it does not match, and pcre_exec
returns negative. I pass a topic from 65 to pcre_exec
, which is the number of characters in a string. I believe that it expects the number of bytes, so I tried increasing the argument to 70, but still get the same result. I do not know what else makes the match unsuccessful. Help before shooting yourself.
(If I try without the PCRE_UTF8
flag, but it matches, but the offset [1] vector is 30, which is the character index immediately before the Unicode character in my input line)
#include "stdafx.h" #include "pcre.h" #include <pcre.h> /* PCRE lib NONE */ #include <stdio.h> /* I/O lib C89 */ #include <stdlib.h> /* Standard Lib C89 */ #include <string.h> /* Strings C89 */ #include <iostream> int main(int argc, char *argv[]) { pcre *reCompiled; int pcreExecRet; int subStrVec[30]; const char *pcreErrorStr; int pcreErrorOffset; char* aStrRegex = "(\\?\\w+\\?\\s*=)?\\s*(call|exec|execute)\\s+(?<spName>\\w+)(" // params can be an empty pair of parenthesis or have parameters inside them as well. "\\(\\s*(?<params>[?\\w,]+)\\s*\\)" // paramList along with its parenthesis is optional below so a SP call can be just "exec sp_name" for a stored proc call without any parameters. ")?"; reCompiled = pcre_compile(aStrRegex, 0, &pcreErrorStr, &pcreErrorOffset, NULL); if(reCompiled == NULL) { printf("ERROR: Could not compile '%s': %s\n", aStrRegex, pcreErrorStr); exit(1); } char* line = "?rt?=call SqlTxFunctionTesting(?înFîéld?,?outField?,?inOutField?)"; pcreExecRet = pcre_exec(reCompiled, NULL, line, 65, // length of string 0, // Start looking at this point 0, // OPTIONS subStrVec, 30); // Length of subStrVec printf("\nret=%d",pcreExecRet); //int substrLen = pcre_get_substring(line, subStrVec, pcreExecRet, 1, &mantissa); }
source share