c A simple wildcard matching instance

Source: Internet
Author: User

Wildcard characters are used to match, different systems on the same wildcard characters,

For example, there is an "_" Wildcard in SQL (instead of one character only) and a "%" wildcard (instead of one or more characters) and must be used with the link operator.

Only wildcard * and, are considered here. , * represents 0 or any number of characters. Represents a single character.

Match int (char *pat,char *str)

{

Switch (*PAT) {

Case ' I ' return!*str;

Case ' * ' return match (PAT+1,STR) | | *str&&match (pat,str+1);

Case '? ' Return *str&&match (pat+1,str+1);

Default return *pat==*str&&match (Pat+1,str=1);

}

}

Call Mathch ("A*B.C", "ALKLB.C") returns 1;


Note the difference from regular expressions:

Wildcard characters are used for matching.

A regular expression (regular expression) is a logical formula for string manipulation, which is used to match a string, consisting of a "rule string" with a predefined set of characters, and a combination of these particular characters, and this "rule string" A filter logic used to express a string, in short, can be regarded as a string matching pattern standard is a description and regulation of the string matching pattern

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.