- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
目标是:这个 json:
{"secretWord1":"private", "something": "\"secretWord2\":\"privateToo\""}
通过 regex_match 转换为:
{"secretWord1":"****", "something": "\"secretWord2\":\"****\""}
我有一个包含三个正则表达式的代码:
std::regex regex1(R"~((\\\"|")((?:[^\\"]*)(?:secretWord1|secretWord2))\1:\1([^\\"]*)\1)~", std::regex_constants::icase);
std::regex regex2(R"~((\\\")((?:[^\\"]*)(?:secretWord1|secretWord2))\1:\1([^\\"]*)\1)~", std::regex_constants::icase);
std::regex regex3(R"~((")((?:[^\\"]*)(?:secretWord1|secretWord2))\1:\1([^\\"]*)\1)~", std::regex_constants::icase);
std::string replaced = someJsonData;
replaced = std::regex_replace(replaced, regex1, "$1$2$1:$1****$1");
replaced = std::regex_replace(std::regex_replace(replaced, regex2, "$1$2$1:$1****$1"), regex3, "$1$2$1:$1****$1");
我想替换 secret 信息并将其隐藏在星星后面。第一个正则表达式在
上失败error_stack: regex_error(error_stack): There was insufficient memory to determine whether the regular expression could match the specified character sequence.
第一个表达式有问题吗?因为其他两个表达式只是相互补充,最终,它完成与 regex1 相同的工作,但当我运行它们时它们运行良好。
我无法在它失败时提供示例代码,但文件不是很大(大约 30kB)。当我尝试使用 JSON 生成器时,regex1 明显比结合使用 regex2+regex3 慢。
最佳答案
我不太了解 C++ 和内存问题,但这似乎非常匹配:
(\\?"(secretword1|secretword2)\\?":\\?")(.*?)(\\?")
https://regex101.com/r/T8pY0V/2
请注意,我强烈建议获取一个 JSON 库,但此正则表达式可能会在紧要关头起作用。您需要找出所有失败的边缘情况。
关于c++ - regex_match 期间的 error_stack,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57558910/
这个问题在这里已经有了答案: Is gcc 4.8 or earlier buggy about regular expressions? (3 个答案) 关闭 6 年前。 我正在尝试对其中包含方括
#include`` #include `` #include `` using namespace std; int main () { try{ std::regex re("(http|ht
我在 site 上测试了正则表达式 [BCGRYWbcgryw]{4}\[\d\]似乎可以在以下 BBCC[0].GGRY[0].WWWW[soln] 中找到匹配项。它与 BBCC[0] 和 GGRY
我正在尝试编写递归下降解析器,并尝试在用户输入的字符串中搜索正则表达式的匹配项。我正在尝试执行以下操作以尝试理解 C++11 提供的库,但我得到了意想不到的结果。 std::string expre
我正在尝试检查 yyyy-mm-dd 格式的日期字符串的格式。我像这样调用 regex_match 函数: if (regex_match(date, regex("/\d{4}-\d{2}-\d{2
我正在尝试使用 std::regex_match()作为 std::count_if() 中的谓词与 std::vector类成员函数中的元素。但是不知道如何正确地将第二个参数(正则表达式值)绕过到函
这是我的代码: #include #include #include using namespace std; int main () { string test = "COPY" ;
我正在使用 C++ 正则表达式。无法掌握以下编程输出。 #include #include #include #include using namespace std; int main(){
我在 XCode 上使用 C++。我想使用 regex_match 匹配非字母字符,但似乎有困难: #include #include using namespace std; int main(
这个问题在这里已经有了答案: Is gcc 4.8 or earlier buggy about regular expressions? (3 个答案) 关闭 5 年前。 我有这段代码片段,是我从
这是我的部分代码 bool CSettings::bParseLine ( const char* input ) { //_asm INT 3 std::string line (
我试图弄清楚我在这个验证规则上做错了什么,因为它说了这个错误。 验证规则: $this->form_validation->set_rules('username', 'Username', 'tri
在我的代码中,我想根据封闭的 <> 括号处理 stirngs。为此,我想遍历字符串并一个一个地替换括号并根据括号内的内容做一些事情。 string msg = "This is an Example<
目标是:这个 json: {"secretWord1":"private", "something": "\"secretWord2\":\"privateToo\""} 通过 regex_match
这是我的程序: #include "stdafx.h" #include #include #include #include using namespace std; int _tmain(
我必须编写一个 C++ 正则表达式,但我无法在 regex_match 上获得正确的结果,因为我是 C++ 的新手。测试字符串为:D10A7;让我们说 unsigned_char[] stringTo
我有一些我认为应该触发的 boost Regex 代码。我是 boost 的新手,但我对 Regex 有一点了解。这是我正在使用的代码。 re = boost::basic_regex(_T("-+\
我想匹配输入字段中给定的字符串。 A sample data could be "hello" -> returns true or "\"" -> returns true or "this is
我知道: 惰性量词匹配:尽可能少(最短匹配) 还知道构造函数: basic_regex( ..., flag_type f = std::regex_constants::EC
这个问题在这里已经有了答案: Simple std::regex_search() code won't compile with Apple clang++ -std=c++14 (3 个答案)
我是一名优秀的程序员,十分优秀!