- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在编译一个启用了 utf8 标志的 PCRE 模式,并试图匹配一个 utf8 char*
字符串,但它不匹配并且 pcre_exec
返回负值.我将主题长度作为 65 传递给 pcre_exec
,这是字符串中的字符数。我相信它需要字节数,所以我尝试将参数增加到 70,但仍然得到相同的结果。我不知道还有什么让比赛失败。在我开枪之前请帮忙。
(但是,如果我尝试不使用标志 PCRE_UTF8
,它会匹配,但偏移 vector [1] 是 30,它是输入字符串中 unicode 字符之前的字符索引)
#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);
}
最佳答案
1)
char * q= "î";
printf("%d, %s", q[0], q);
输出:
63、?
2) 您必须使用 PCRE_BUILD_PCRE16(或 32)和 PCRE_SUPPORT_UTF 重建 PCRE。并使用 pcre16.lib 和/或 pcre16.dll。然后你可以试试这个代码:
pcre16 *reCompiled;
int pcreExecRet;
int subStrVec[30];
const char *pcreErrorStr;
int pcreErrorOffset;
wchar_t* aStrRegex = L"(\\?\\w+\\?\\s*=)?\\s*(call|exec|execute)\\s+(?<spName>\\w+)("
// params can be an empty pair of paranthesis or have parameters inside them as well.
L"\\(\\s*(?<params>[?,\\w\\p{L}]+)\\s*\\)"
// paramList along with its paranthesis is optional below so a SP call can be just "exec sp_name" for a stored proc call without any parameters.
L")?";
reCompiled = pcre16_compile((PCRE_SPTR16)aStrRegex, PCRE_UTF8, &pcreErrorStr, &pcreErrorOffset, NULL);
if(reCompiled == NULL) {
printf("ERROR: Could not compile '%s': %s\n", aStrRegex, pcreErrorStr);
exit(1);
}
const wchar_t* line = L"?rt?=call SqlTxFunctionTesting( ?inField?,?outField?,?inOutField?,?fd? )";
const wchar_t* mantissa=new wchar_t[wcslen(line)];
pcreExecRet = pcre16_exec(reCompiled,
NULL,
(PCRE_SPTR16)line,
wcslen(line), // length of string
0, // Start looking at this point
0, // OPTIONS
subStrVec,
30); // Length of subStrVec
printf("\nret=%d",pcreExecRet);
for (int i=0;i<pcreExecRet;i++){
int substrLen = pcre16_get_substring((PCRE_SPTR16)line, subStrVec, pcreExecRet, i, (PCRE_SPTR16 *)&mantissa);
wprintf(L"\nret string=%s, length=%i\n",mantissa,substrLen);
}
3)\w = [0-9A-Z_a-z]。它不包含 unicode 符号。
4) 这真的很有帮助:http://answers.oreilly.com/topic/215-how-to-use-unicode-code-points-properties-blocks-and-scripts-in-regular-expressions/
5) 来自 PCRE 8.33 源 (pcre_exec.c:2251)
/* Find out if the previous and current characters are "word" characters.
It takes a bit more work in UTF-8 mode. Characters > 255 are assumed to
be "non-word" characters. Remember the earliest consulted character for
partial matching. */
关于c - PCRE 不匹配 utf8 字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18329532/
运行 uwsgi 时,我收到以下消息: !!! no internal routing support, rebuild with pcre support !!! 我已经使用以下命令安装了 pcre
我对 PCRE(Perl 兼容正则表达式)的强大功能很感兴趣,并想知道它们是否有可能成为所有主要语言的事实上的方法(我对 Java 感兴趣)。如有必要,我准备使用图书馆。 我也无法在 SO 中找到描述
我正在尝试生成一些可以触发 snort 警报的跟踪以测试 snort 的性能。但是在一些规则中有一些pcre选项包含/R,我不明白。 例如,在一个snort规则pcre中有一个pcre选项:"/^(\
什么是 PCRE 兼容语法? C# PCRE 兼容吗?从维基百科我发现了这个: Perl Compatible Regular Expressions (PCRE) is a regular expr
我迷路了。我有 Linux CentOS 操作系统。我试图在 pcre 网站上下载的 pcre 包中找到 pcre.h。我也按照安装指南中的说明进行了配置,但没有运气。有帮助吗? 最佳答案 最新版本叫
我正在尝试使用以下命令配置和制作 pcre ./configure CC="gcc" CFLAGS="-maix64" CXX="gcc" CXXFLAGS="-maix64" LDFLAGS="-L
我想要一个 Perl 正则表达式来匹配 std::foo但不匹配 std::foo::bar .这是我到目前为止: /((?
我想这或多或少是一个由两部分组成的问题,但首先是基础知识:我正在编写一些 PHP 以使用 preg_match_all 来查找以 {} 结尾的字符串的变量。然后它遍历每个返回的字符串,用 MySQL
我有以下文字: aabbaa aa bbc aa bbg aa bbd aa 我想找到 以 bb 开头且 不在 aa 和 aa 之间 的单词,而不管使用 PCRE 的匹配单词之
PCRE 正则表达式 /..(?<=(.)\1)/无法编译:“后向断言中不允许子模式引用。”有趣的是,它似乎在前瞻中是可以接受的,例如 /(?=(.)\1)../ , 只是不在回顾中。 是否有技术原因
我想一步一步地理解以下模式。 /\p{L}/u /u 是一个修饰符(http://www.php.net/manual/en/reference.pcre.pattern.modifiers.php)
我有一个带有空值的文本源,我需要将它们与我的正则表达式模式一起拉出。正则表达式甚至可以匹配空字符吗? 当我的模式拒绝匹配时,我才意识到我有它们,当我将它粘贴到 Notepad++ 时,它显示了所有的空
我想演示我可以用制表符替换空格缩进,但只能替换每行的前导空格。 我想我可以通过可变宽度的后视来实现这一点。不幸的是,这在 PCRE 中是不允许的。 s/(?<=^|(?:[ ]{3})+)[ ]{3}
我必须在Python中基于PCRE解析一些字符串,而且我不知道该怎么做。 我想解析的字符串如下所示: match mysql m/^.\0\0\0\n(4\.[-.\w]+)\0...\0/s p/M
在 Notepad++ 6.5.1 中,我需要替换引号对中的某些模式。我想将替换保存为宏的一部分,因此所有替换都需要一步完成。 例如,在下面的字符串中,将引号对中的所有“a”字符替换为破折号,而引号对
使用 PCRE 库...想要查找最多包含已知空格数的单词字符串。 即标记之间有 5 个空白字符。 foo bar foo bar foo bar = 第一个 foo 和最后一个 bar 之间....有
我想演示我可以用制表符替换空格缩进,但只能替换每行的前导空格。 我想我可以通过可变宽度的后视来实现这一点。不幸的是,这在 PCRE 中是不允许的。 s/(?<=^|(?:[ ]{3})+)[ ]{3}
谁能举个例子例如对于这个字符串 wordride plain fire 用另一个字母替换空格 例如替换 第一个匹配空格前第三个字母的空格 例如我想在单词后替换字符用这个 (?:\G(?!^)|w
我很惊讶不容易找到类似问题的答案。我想匹配某些功能中的所有内容。这个想法是删除无用的功能。 foo(some (content)) --> some (content) 所以我试图匹配函数调用中可以包
我希望将大量模式与 Web 文档中的各种 HTML 元素、属性和文本相匹配。 例如,我可能对 的内容感兴趣元素并有一个这样的正则表达式: pcre *test_filter = pcre_compi
我是一名优秀的程序员,十分优秀!