C++-正则表达式库-VerbalExpressions

关于

CppVerbalExpressions是麻省理工学院构建的 C++ 正则表达式库

项目地址 github.com

支持 c++11 std::regex 或者 boost::regex

使用

头文件

verbalexpressions.hpp

类及成员函数

Items

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//等价于 .*
.anything()
//等价于 [^value]*
.anything_but( const std::string & value )
//等价于 .+
.something()
//等价于 [^value]+
.something_but(const std::string & value)
//等价于 $
.end_of_line()
//等价于 ^(value)$
.find( const std::string & value )
//等价与 [value]?
.maybe( const std::string & value )
//等价与 ^
.start_of_line()
//等价于 (value)
.then( const std::string & value )

Special characters and groups

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//等价于 [value]
.any( const std::string & value )
//同 any(value)
.any_of( const std::string & value )
//等价于 ([\n]|[\r\n])
.br()
//同 br()
.linebreak()
//等价于 for(auto& i:args) ([i.first-i.second...])
.range( const std::vector<std::pair<std::string, std::string>> & args )
//等价于 [a-b]
.range( const std::std::string & a, const & std::string b )
//等价于 \t
.tab()
//等价于 \w+
.word()

Modifiers

1
2
3
4
5
6
//等价于 /i
.with_any_case()
//等价于 /m
.search_one_line()
//等价于 /g
.search_global()

Functions

1
2
3
4
//将source中匹配的部分替换成value
.replace( const std::string & source, const std::string & value )
//测试value是否匹配
.test( const std::string& value )

Other

1
2
3
4
5
6
//等价于直接在正则表达式后添加value
.add(value)
//等价于 +value
.multiple( const std::string & value )
//等价于 (之前的正则)|(value)
.alt( const std::string& value )