【发布时间】:2012-03-06 22:37:54
【问题描述】:
我有一个用户输入的字符串,我的数据库中有我的正则表达式,我可以根据数据库中的正则表达式检查输入字符串。
但是现在我需要在我的数据库中添加另一个列,它将保存另一个正则表达式,但我想使用相同的 for 循环来检查输入字符串是否与我的新正则表达式一样,但在我的第一个循环结束时。但我想对同一个字符串使用这个新表达式
即\\D\\W\\D \\d
- 对有效的输入字符串使用数据库中的正则表达式
- 在同一个循环中添加新的正则表达式和企业并检查同一个字符串 - 不起作用
我的代码如下
std::string errorMessages [2][2] = {
{
"Correct .R\n",
},
{
"Free text characters out of bounds\n",
}
};
for(int i = 0; i < el.size(); i++)
{
if(el[i].substr(0,3) == ".R/")
{
DCS_LOG_DEBUG("--------------- Validating .R/ ---------------");
output.push_back("\n--------------- Validating .R/ ---------------\n");
str = el[i].substr(3);
split(st,str,boost::is_any_of("/"));
DCS_LOG_DEBUG("main loop done");
for (int split_id = 0 ; split_id < splitMask.size() ; split_id++ )
{
boost::regex const string_matcher_id(splitMask[split_id]);
if(boost::regex_match(st[split_id],string_matcher_id))
{
a = errorMessages[0][split_id];
DCS_LOG_DEBUG("" << a );
}
else
{
a = errorMessages[1][split_id];
DCS_LOG_DEBUG("" << a);
}
output.push_back(a);
}
DCS_LOG_DEBUG("Out of the loop 2");
}
}
如何从数据库中检索我的正则表达式,并在此循环完成后对同一字符串使用这个新的正则表达式。
字符串是 - shamari
我想添加的正则表达式 - "\\d"
有不懂的可以问我
【问题讨论】:
-
听起来您只是想添加更多代码...您只是尝试编写它吗?你的问题听起来像“我如何在我的代码中做不止一件事情?”
-
是的,我需要添加更多代码,但如您所见,我使用循环遍历正则表达式和输入字符串,但我只想添加新的正则表达式,但结果显示用标题分隔它们