[英]How does Regex work in Boost Regex C++
我目前正在使用Boost Regex庫,並試圖獲取C ++中稱為arguments的函數。 例如,我有一個帶有HTML的頁面,並且有一個名為JavaScript的函數,我們將其稱為
XsrfToken.setToken('54sffds');
我目前擁有的東西,無法正常工作。
std::string response = request->getResponse();
boost::regex expression;
if (type == "CSRF") {
expression = {"XsrfToken.setToken\('(.*?)'\)"};
}
boost::smatch results;
if (boost::regex_search(response, results, expression)) {
std::cout << results[0] << " TOKEN" << std::endl;
}
其中response是HTML網頁,而expression是正則表達式。 條件語句正在運行,因此我認為我的正則表達式有問題,但我不知道。
[編輯]
忘記提及正則表達式是從PHP提取的,並且可以在PHP正則表達式檢查器/調試器中使用
您的錯誤不是使用regex
語法?
在*
之后是多余的,但在C++
字符串常量文字中:反斜杠char應該用反斜杠轉義:
#include <boost/regex.hpp>
#include <iostream>
#include <string>
std::string response("XsrfToken.setToken('ABC')");
boost::regex expression("XsrfToken.setToken\\('(.*?)'\\)");
int main() {
boost::smatch results;
if (boost::regex_search(response, results, expression)) {
std::cout << results[0] << " TOKEN" << std::endl;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.