Share a piece of code

Source: Internet
Author: User

Read 《CodeThe beauty of the ", see a piece of SVN code, very elegant, posted to share:

Is a simple regular code that supports ^ $. It demonstrates the elegant processing of special cases, the Compact combination of the incremental operation of pointer and C and the implicit conversion of Boolean values, and the clever use of recursive ideas to solve the problem:

 int match (char * Regexp, char * text) {If (Regexp [0] = '^') {return matchhere (Regexp + 1, text) ;}do {If (matchhere (Regexp, text) return 1 ;} while (* Text ++! = '\ 0'); Return 0;} int matchhere (char * Regexp, char * Text) {If (Regexp [0] =' \ 0') return 1; if (Regexp [0] = '*') return matchstar (Regexp [0], Regexp, text ); if (Regexp [0] = '$' & Regexp [1] = '\ 0') return * text =' \ 0 '; if (Regexp [0] = * Text | Regexp [0] = 'C') & * text! = '\ 0') return matchhere (Regexp + 1, text + 1);} int matchstar (char C, char * Regexp, char * text) {do {If (matchhere (Regexp, text) return 1;} while (* text! = '\ 0' & (* Text ++ = c | C ='. ') return 0 ;}

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.