您当前的位置: 首页 >  搜索

qianbo_insist

暂无认证

  • 0浏览

    0关注

    399博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

再探正则表达式c++-html中搜索url

qianbo_insist 发布时间:2021-07-08 17:48:52 ,浏览量:0

正则基础 字符
[a-z]    // 匹配所有的小写字母
[A-Z]    // 匹配所有的大写字母
[a-zA-Z]   // 匹配所有的字母
[0-9]      // 匹配所有的数字
[0-9\.\-]      // 匹配所有的数字、句号、减号
[ \n\f\r\t\v]  // 匹配所有的空白字符(空格、换行符、换页符、回车符、水平制表符、垂直制表符)
数字
^[0-9]{1,}$           // 匹配所有的正数
^[0-9]+$              // +与{1,}相等,表示前面的内容可以是1个或多个
^\-{0,1}[0-9]{1,}$    // 匹配所有的整数
^\-?[0-9]+$           
^\-{0,1}[0-9]{0,}\.{0,1}[0-9]{0,}$  // 匹配所有小数的正则
^\-?[0-9]{0,}\.?[0-9]{0,}$    // ?与{0,1}相等,表示前面的内容是可选的
^\-?[0-9]*\.?[0-9]*$          // *与{0,}相等,表示前面的内容可以是0个或多个
c++ regex

c++ regex 可以使用多种方式,std::regex_match,std::regex_search,使用这两种方式都很方便 ,我们下面使用多种方式来做匹配,最后使用search 来搜索网页中的url

#include 
#include 
#include 
#include 
using namespace std;
int main()
{
	// 简单正则表达式匹配
	std::string fnames[] = { "addc
  • abdd", "dddddddddddddddd链接", "aaa.html", "dd adf aaa.png" }; std::regex html_regex("[a-z]+\\.html"); for (const auto &fname : fnames) { std::cout
    关注
    打赏
    1663161521
    查看更多评论
    0.0431s