不同的正则表达式匹配结果在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;
}

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

相关内容

热门资讯

三分钟了解(wpk稳赢)外挂透... 1、三分钟了解(wpk稳赢)外挂透明挂辅助APP(透视)软件透明挂(有挂详情)-哔哩哔哩。2、wpk...
程序员教你(来玩app)外挂透... 《来玩app软件透明挂》是一款多人竞技的来玩app辅助透视游戏,你将微扑克对手来到同一个战场,为至高...
透明有挂!wpk挂(WepOk... 透明有挂!wpk挂(WepOke)外挂透明挂辅助工具(辅助挂)安装教程(有挂教程)-哔哩哔哩1、很好...
透明私人局(德扑之星电脑)外挂... 透明私人局(德扑之星电脑)外挂透明挂辅助挂(辅助挂)德州ai机器人(有挂攻略)-哔哩哔哩是一款可以让...
科技分享(德扑分析)外挂透明挂... 科技分享(德扑分析)外挂透明挂辅助插件(透视)辅助透视(2022已更新)(哔哩哔哩)1、完成德扑分析...
技术分享!wepoke有挂(w... 技术分享!wepoke有挂(wePoKe)外挂透明挂辅助软件(辅助挂)安装教程(存在有挂)-哔哩哔哩...
总算了解(德州wpk)外挂透明... 总算了解(德州wpk)外挂透明挂辅助工具(透视)透视辅助(有挂实锤)-哔哩哔哩,支持语音通讯、好友开...
1分钟了解(wpk辅助透视)外... 1分钟了解(wpk辅助透视)外挂透明挂辅助app(透视)透视辅助(2023已更新)(哔哩哔哩);(需...
玩家必知教程!wEPoke(w... 玩家必知教程!wEPoke(wEPoke)外挂透明挂辅助app(透视)wpk教程(证实有挂)-哔哩哔...
透视科技(约局吧)外挂透明挂辅... 透视科技(约局吧)外挂透明挂辅助APP(辅助挂)软件透明挂(存在有挂)-哔哩哔哩;(需添加指定薇75...