[LeetCode]-010-Regular_Expression_Matching
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 }