我有一个功能,使字符串:
select * from run_on_hive(server('hdp230m2.labs.teradata.com'),username('vijay'),password('vijay'),dbname('default'),query('analyze table default.test01 compute statistics'));
至:
select * from run_on_hive(server('hdp230m2.labs.teradata.com'),username('vijay'),'****',dbname('default'),query('analyze table default.test01 compute statistics'));
该函数如下所示:
static SimpleRegexMask::Ptr newUDFMask(const String &udfName, const int paramPos)
{
return SimpleRegexMask::newInstance(
udfName,
udfName + "([^[:alpha:]]*)\\((([^,]*,){" + toString(paramPos - 1) + "})([^,]*)(,[^\\)]*)\\)",
udfName + "\\1\\(\\2'****'\\5\\)"
);
}
这些是以上功能之一。我希望它能解释我要做什么
static Ptr newInstance(
const String &baseRegex,
const String &replaceRegex,
const String &matchFormatString
)
{
return new SimpleRegexMask(baseRegex, replaceRegex, matchFormatString);
}
SimpleRegexMask::SimpleRegexMask(
const String &baseRegex,
const String &replaceRegex,
const String &matchFormatString
)
{
try {
basePattern_ = boost::regex(
baseRegex, boost::regex_constants::icase|boost::regex_constants::perl
);
replacePattern_ = boost::regex(
replaceRegex, boost::regex_constants::icase|boost::regex_constants::perl
);
matchFormatString_ = matchFormatString;
} catch (const boost::regex_error& ex) {
// programming error i.e. the regex supplied is not valid
NOT_REACHED;
}
}
但是,我想将字符串修改为
select * from run_on_hive(server('hdp230m2.labs.teradata.com'),username('vijay'),password('****'),dbname('default'),query('analyze table default.test01 compute statistics'));
我应该如何修改上述功能来做到这一点?我要去哪里错了。请告诉我。TIA。
您可以使用
return SimpleRegexMask::newInstance(
udfName,
"(" + udfName + "[^[:alpha:]]*)\\(((?:[^,]*,){" + toString(paramPos - 1) + "}[^,(]*\\(['\"])[^,'\"]*(['\"]\\),[^)]*)\\)",
"\\1\\(\\2****\\3\\)"
);
请参阅regex演示。
我在这里优化了捕获组的用法(减少了其数量),并使用[^,(]*\\(['\"])[^,'\"]*(['\"]\\)
模式password
通过以下方式匹配该部分:捕获password('
或password("
进入组2,然后匹配,
,"
或以外的任何0+字符'
,然后将')
或捕获")
到后续捕获组中。
请注意,UDF名称被捕获到组1中,您无需在替换字符串中对其进行硬编码。因此,如果它RUN_ON_HIVE
在字符串中,RUN_ON_HIVE
即使您run_on_hive
在模式中,它也将出现在结果中(因为您使用的是不区分大小写的修饰符)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句