如何匹配C ++中的正则表达式中的\0字符? [英] How can I match the \0 character in a regex in C++?

查看:420
本文介绍了如何匹配C ++中的正则表达式中的\0字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要匹配文本'\0'与我将匹配'a'或'b'相同的正则表达式。 (C ++中字符常量的正则表达式)。我试过一堆不同的regexes,但还没有得到一个成功的一个。我最近的尝试:

I need to match the text '\0' with the same regex that I would match 'a' or 'b'. (a regex for a character constant in C++). I've tried a bunch of different regexes, but haven't gotten a successful one yet. My latest attempt:

^['].|\\0[']

我试过的大部分的东西给了seg错误,所以这是真的最近我得到的。

Most of the other things I've tried have given seg faults, so this is really the closest I've gotten.

推荐答案

正则表达式(在这种情况下,使用C头)是:

The regex that works (in this instance, using the C header ) is:

^('(.|([\\]0))')

$ b b

感谢@WhozCraig的帮助!

Thanks to @WhozCraig for the help!

这篇关于如何匹配C ++中的正则表达式中的\0字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆