About the Pcre regular expression library Libpcre

Source: Internet
Author: User

The header file for STD regex is already included in GCC 4.8

But there is no implementation, so the link is a failure

GCC 4.9 fully supports the Regex of C + + 11.

Before 4.9, you can seek a boost for the regex.

However, I am more familiar with the implementation of Pcre, Perl-based regular expressions.

Download source code, unzip

Configure the library to cross-compile, generate only static libraries, and configure the Pcre code as follows:

#!/bin/SHExport RootDir="${pwd}"CD Pcre-8.36/Export Cross_compile="Arm-linux-androideabi"Export AR=${cross_compile}-arExport as=${cross_compile}-Asexport LD=${cross_compile}-LDExport Ranlib=${cross_compile}-Ranlibexport CC=${cross_compile}-GCCExport CXX=${cross_compile}-g++Export NM=${cross_compile}-nm./configure--prefix=${rootdir}/build/pcre--target=${cross_compile}--host=${cross_compile}--build=i686-linux-- Disable-shared

Perform make && make install build target file

Next we start using the Libpcre library

Enumerate all matching items and print the results, with the following code:

1#include"pcre.h"2#include <string>3#include <vector>4#include <iostream>5 6 intMainvoid)7 {8     Const intOveccount = -; 9STD::stringSrc_string ="saturday=6 and sunday=7, but some fridays=5 joke=102 also.";TenSTD::stringRegex_string ="\\w+=\\d+"; One     BOOLB_case =false; A  -     Const Char*error; -     intErroffset; the     intOvector[oveccount]; -STD::VECTOR&LT;STD::string>sfinds; -pcre* re = Pcre_compile (Regex_string.c_str (), b_case? Pcre_caseless:0, -&error, &Erroffset, NULL); +     if(RE) -     {    +Unsignedintoffset =0;  AUnsignedintLen =src_string.size (); at         Const Char* str =src_string.c_str (); -         intrc =0; -          while(Offset < len && (rc = pcre_exec (RE),0, str, Len, offset,0, Ovector, Oveccount)) >=0) -         { -Std::cout <<"Find Count:"<< RC <<Std::endl; -              for(inti =0; I < RC; ++i) in             { -                 intS_len = ovector[2*i+1]-ovector[2*i]; toSTD::stringSfind = Src_string.substr (ovector[2*i], s_len); + Sfinds.push_back (sfind); -             } theoffset = ovector[1]; *         } $         Panax Notoginseng Pcre_free (re); -     }    the  +      for(size_t i =0; I < sfinds.size (); ++i) AStd::cout <<"*"<<sfinds[i] <<"* "; theStd::cout <<Std::endl; +  -     return 0; $}

Compile and run regex with the output as:

Find Count:1
Find Count:1
Find Count:1
Find Count:1
*saturday=6* *sunday=7* *fridays=5* *joke=102*

About the Pcre regular expression library Libpcre

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.