不同的正则表达式匹配结果在ICU库、Rust和PCRE(https://regexr.com/)之间不一致
创始人
2025-01-08 21:30:27
0

根据问题产生的原因,可能需要对每个工具的正则表达式实现进行详细的比较和调试,直至问题被解决。下面是一个示例,其中我们尝试使用具有15个连续数字的正则表达式,在三个工具中都进行匹配,并将它们的结果进行比较。

ICU(C++)代码示例:

#include 
#include 
using namespace std;
int main() {
    UErrorCode error = U_ZERO_ERROR;
    UnicodeString pattern("([0-9]{15})");
    RegexMatcher matcher(pattern, 0, error);
    UnicodeString input("123456789012345678901234567890");
    matcher.reset(input);
    while(matcher.find()){
    cout << "Matched: ";
    cout << matcher.group()<< endl;
    }
    return 0;
}

Rust 代码示例:

use regex::Regex;
fn main() {
    let re = Regex::new(r"([0-9]{15})").unwrap();
    let text = "123456789012345678901234567890";
    for capture in re.captures_iter(text) {
        println!("Matched: {}", capture.get(0).unwrap().as_str());
    }
}

PCRE 代码示例:

#include 
#include 
#include 
int main(){
    const char *re = "([0-9]{15})";
    pcre *compiled_re;
    const char *error;
    int er_offset;
    compiled_re = pcre_compile(re, 0, &error, &er_offset, NULL);
    char* subject = "123456789012345678901234567890";
    int ovector[30];
    int rc = pcre_exec(compiled_re, NULL, subject, strlen(subject), 0, 0, ovector, 30);
    while(rc >= 0){
        printf("Matched: %.*s\n", ovector[1] - ovector[0], subject + ovector[0]);
        rc = pcre_exec(compiled_re, NULL, subject, strlen(subject), ovector[1], 0, ovector, 30);
    }
    pcre_free(compiled_re);
    return 0;
}

使用上述代码,我们可以比较三个工具的输出结果,以确定任何不一致或不准确的地方,并做出必要的调整。

相关内容

热门资讯

透视实锤!aapoker免费透... 透视实锤!aapoker免费透视脚本(透视)aapoker能控制牌吗,AA德州教程(有挂规律);1、...
透视ai!wepoker有人用... 透视ai!wepoker有人用过吗,黑侠破解wepoker(详细一直输的号能继续打)1、该软件可以轻...
透视黑科技!aapoker怎么... 透视黑科技!aapoker怎么控制牌(透视)aapoker如何设置胜率,普及教程(有挂揭秘);1、a...
透视玄学!wepoker脚本,... 透视玄学!wepoker脚本,wepokerplus开挂(详细透视底牌);1、进入到wepokerp...
透视模拟器!aapoker发牌... 透视模拟器!aapoker发牌逻辑(透视)aapoker免费透视脚本,2025新版(有挂规律)1、在...
透视安装!wepoker透视有... 透视安装!wepoker透视有用吗,wepoker轻量版透视(详细正确养号方法)1、让任何用户在无需...
透视好友房!aapoker怎么... 透视好友房!aapoker怎么选牌(透视)aapoker透视插件,2025新版(有挂工具);1、许多...
透视新版!wepoker透视脚... 透视新版!wepoker透视脚本下载,wepoker游戏的安装教程(详细破解游戏盒子)小薇(透视辅助...
透视中牌率!aapoker公共... 透视中牌率!aapoker公共底牌(透视)aapoker辅助怎么用,专业教程(有挂规律)1、下载好a...
透视科技!wepoker有没有... 透视科技!wepoker有没有透视方法,wepoker破解工具(详细作弊辅助)wepoker有没有透...