码迷,mamicode.com
首页 > 其他好文 > 详细

[LeetCode]-010-Regular_Expression_Matching

时间:2016-04-15 19:47:14      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:

Implement regular expression matching with support for ‘.‘ and ‘*‘.

‘.‘ Matches any single character.

‘*‘ Matches zero or more of the preceding element.

The matching should cover the entire input string (not partial).

The function prototype should be: bool isMatch(const char *s, const char *p)

Some examples:

isMatch("aa","a") → false

isMatch("aa","aa") → true

isMatch("aaa","aa") → false

isMatch("aa", "a*") → true

isMatch("aa", ".*") → true

isMatch("ab", ".*") → true

isMatch("aab", "c*a*b") → true

题目:正则表达式匹配

 1 public class Solution{
 2     public boolean isMatch(String s, String p) {
 3         Pattern pattern = Pattern.compile(p);
 4         Matcher matcher = pattern.matcher(s);
 5         return matcher.matches();
 6     }
 7     
 8     public static void main(String[] args){
 9         String param1 = "aa",param2 = ".*";
10         if(args.length==2){
11             param1 = args[0];
12             param2 = args[1];
13         }
14         Solution solution = new Solution();
15         boolean res = solution.isMatch(param1,param2);
16         System.out.println(res);
17     }
18 }

 

[LeetCode]-010-Regular_Expression_Matching

标签:

原文地址:http://www.cnblogs.com/lianliang/p/5396323.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!