C Regular-RegEx

Source: Internet
Author: User
Tags preg

I have been busy recently, and I have never written a blog. I finally got my own time yesterday and continue to learn ~~

 

For details about the c Regular Expression, man RegEx can see a lot, just paste the code here and describe what you need to pay attention:

 

1. If you need to output special characters, you need to reverse the meaning twice.

2. Viewing various statuses is a good habit.

3. Match [0] is the original data. If you want to find the matching result, it starts with match [1 ].

 

Code ~~

# Include <stdio. h> <br/> # include <RegEx. h> <br/> # include <sys/types. h> <br/> # include <string> <br/> int main () <br/> {<br/> regex_t reg; <br/> size_t error_len; <br/> int ret = 0; <br/> char Buf [1024]; <br/> const char * test = "url = [http://hit.love.wenwen.com]/n "; <br/> const char * preg = "url = //[(. *?) //] "; <Br/> If (ret = regcomp (, preg, reg_extended ))! = 0) {<br/> If (regerror (Ret, Buf, 1024) {<br/> printf ("comp Reg failed: % s/n ", buf); <br/>}< br/> return 1; <br/>}< br/> regmatch_t match [4]; <br/> If (ret = regexec (, test, 4, match, reg_notbol ))! = 0) {<br/> If (regerror (Ret, Buf, 1024) {<br/> printf ("Match Reg failed: % s/n ", buf); <br/>}< br/> return 1; <br/>}else {<br/> int Index = 1; <br/> while (Match [Index]. rm_so! =-1) {<br/> printf ("Match % d: % s/n", index, <br/> STD: string (test + match [Index]. rm_so, test + match [Index]. rm_eo ). c_str (); <br/> + index; <br/>}< br/> <br/> regfree (); <br/> return 0; <br/>}

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.