我的文字是
< <footnotes><footnote><info><![CDATA[Some text ‘ ”https://www.google.com”> AAAA OR ” https://www.google.com”> AAAA OR ” https://www.google.com”> AAAA OR ” https://www.google.com”> AAAA’]]></info></footnote></footnotes><resources></resources>
我需要找到第一个"https"
到"]]"
的文字,我能够这样做:
(?=https).*?(?=\]\])
但是如果我必须找到"info"
文字,那么第一个"https"
到"]]"
会怎么样?
有没有办法删除文本之间的任何字符?如果我在"https"
到"]]"
之间收到文字,我必须从结果字符串中删除所有"OR"
?
所以我的正则表达式的最终结果将是
https://www.google.com”> AAAA ” https://www.google.com”> AAAA ” https://www.google.com”> AAAA ” https://www.google.com”> AAAA’
如何使用单个正则表达式进行操作?
答案 0 :(得分:1)
通常,在解析嵌套内容(如XML或HTML)时,应使用正确的解析器,而不是单个正则表达式。话虽如此,以下模式似乎有效,至少对于您给出我们给出的要求的样本数据:
class Log
{
public:
Log()
: m_filename( "dafault.log" )
{}
// if you wanna give other names eventually...
Log( const std::string & p_filename )
: m_filename( p_filename )
{}
virtual ~Log()
{
// implement your writeToFile() with std::ofstream
writeToFile( m_filename, m_stream, true );
}
template< typename T >
Log & operator<<( const T & p_value )
{
m_stream << p_value;
return *this;
}
private:
std::string m_filename;
std::ostringstream m_stream;
};
从上面捕获的文字是出现在std::endl
标记之后和CDATA子句的双结束括号之前的Google网址。