不同的正则表达式匹配结果在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 ai辅助!wPk的确真... wpk ai辅助!wPk的确真的有挂,wpK的确真的有挂,2025新版(有挂黑科技);1、下载好wp...
WePoKe透明挂!wepko... WePoKe透明挂!wepkoe有外 挂,WepokE的确是有挂的,细节方法(有挂方法);原来确实真...
德州之星辅助!德扑之星真破解套... 德州之星辅助!德扑之星真破解套路,菠萝德州切实有挂(详细ai辅助有用教程)是一款可以让一直输的玩家,...
wpk有辅助挂!wpk透视辅助... wpk有辅助挂!wpk透视辅助器(wpK)就是真的有挂-详细透视教程1.wpk ai辅助创建新账号,...
wepoke智能ai!wepo... wepoke智能ai!wepoke计算辅助,wepoke软件透明挂存在,微扑克教程(有挂脚本)1、许...
德州ai辅助软件!德州之星有外... 德州ai辅助软件!德州之星有外 挂,德州扑克切实存在有挂(详细猫腻教程);人气非常高,ai更新快且高...
wpk ai辅助(wpK)wp... wpk ai辅助(wpK)wpk微扑克辅助(透视)一直真的有挂(分享教程)1、下载好微扑克辅助软件之...
WePoKe透明挂!wepok... WePoKe透明挂!wepoke美元局稳,wEpOke原来真的有挂,细节揭秘(有挂规律);支持2-1...
德州之星插件!德州辅助软件开发... 德州之星插件!德州辅助软件开发定制,云扑克德州本来是有挂(详细辅助挂教程)1、每一步都需要思考,不同...
wpk透视辅助工具!wpk数据... wpk透视辅助工具!wpk数据透视(WPk)一贯真的有挂-详细辅助挂教程;1、点击下载安装,wpk插...