boost 库 正则 使用一则 -------- 歌词文件信息提取
2012-07-20 12:50
225 查看
说明参考注释.....
本文出自 “冰狐浪子的博客” 博客,请务必保留此出处http://bhlzlx.blog.51cto.com/3389283/936179
#include <iostream> #include <fstream> #include <string> #include <boost/regex.hpp> using namespace std; #define BUFFER_SIZE 1024 char buffer[BUFFER_SIZE]; //下边这个正则有4个匹配项,第一个是匹配字串的全部,第二个是<time>第三个是(\.\d+),即百分秒,第四个是歌词信息 boost::regex reg_lyricItem("(?<time>\\[\\d\\d\\:\\d\\d(\\.\\d+)?\\])(?<lyric>[^\\n\\[]+)?"); int main() { ifstream fs("riya - 小さなてのひら.txt",ios::in); cout<<fs.good()<<endl; string line; // 一行一行取 while(fs.getline(buffer,BUFFER_SIZE)) { // 一行里可能有多句 line = string(buffer); // 关键数据结构 变量定义 //存放结果 boost::match_results<std::string::const_iterator> result; //迭代器 std::string::const_iterator begin = line.begin(),end = line.end(); while(boost::regex_search( begin, end, result, reg_lyricItem, boost::match_default ) ) { //可以通讯result .matched来查看这一部分是否被匹配,如果匹配再进行相应处理也不迟,这里简化没有判断. cout<<string(result[1].first,result[1].second)<<" "<<string(result[3].first,result[3].second)<<endl; //假设这一行有多句,接着上句的最后向后分析 begin = result[0].second; } } cout<<fs.rdstate(); return 0; }
本文出自 “冰狐浪子的博客” 博客,请务必保留此出处http://bhlzlx.blog.51cto.com/3389283/936179
相关文章推荐
- Java使用正则表达式解析LRC歌词文件
- [Boost]_[使用boost库的正则匹配模块替换字符串]
- Visual Studio 2017中使用正则修改部分内容 如何使用ILAsm与ILDasm修改.Net exe(dll)文件 C#学习-图解教程(1):格式化数字字符串 小程序开发之图片转Base64(C#、.Net) jquery遍历table为每一个单元格取值及赋值 。net加密解密相关方法 .net关于坐标之间一些简单操作
- 使用 boost::property_tree::ptree 读取配置文件
- awk 系列:如何使用 awk 和正则表达式过滤文本或文件中的字符串
- 使用Boost.Iostreams实现bzip2格式文件流
- VS2008使用boost的正则表达库regex的环境配置
- spark读取hdfs文件的路径使用正则表达式
- php经典实例使用正则动态修改配置文件
- 使用boost中的filesystem类库遍历某个目录所有的文件
- [Boost]_[使用boost库的正则匹配模块替换字符串]
- php经典实例使用正则动态修改配置文件
- C#使用正则表达式读取log4net日志文件
- topCoder上一则关于正则表达式的文章-简要介绍了其语法和使用方法
- 使用Linux正则表达式灵活搜索文件中的文本
- c++ boost正则使用
- 学习 Linux,101: 使用正则表达式搜索文本文件
- PHP经典实例教程(使用正则动态修改配置文件)
- 关于ultraedit的使用,利用正则表达式过滤有用信息到新的文件中
- c++ boost正则使用