The regular expression match of the sword Point offer (58)

Source: Internet
Author: User

Title Description

Please implement a function to match the include '. ' And the regular expression of ' * '. The characters in the pattern '. ' Represents any character, and ' * ' means that the character preceding it can appear any time (0 times). In the subject, the match refers to all characters of the string that match the entire pattern. For example, the string "AAA" matches the pattern "a.a" and "ab*ac*a", but does not match "aa.a" and "Ab*a"

Code:

<span style= "color: #000099;" >public class Solution {public     Boolean match (char[] str, char[] pattern)    {          if (str.length==0&& pattern.length==0) return true;        if (str==null| | Pattern==null) return false;        else{       stringbuffer sb=new stringbuffer ();        StringBuffer sf=new StringBuffer ();        for (int k=0;k<str.length;k++)            sb.append (Str[k]);        String s1=sb.tostring ();         for (int k=0;k<pattern.length;k++)            sf.append (Pattern[k]);        String s2=sf.tostring ();         return s1.matches (s2);}}    </span>


The regular expression match of the sword Point offer (58)

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.