Regular Expression Matching
2015-04-16 17:05
239 查看
'.' 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
偷个懒:
import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class Solution
{
public boolean isMatch(String s, String p) {
Pattern pattern = Pattern.compile(p);
Matcher matcher = pattern.matcher(s);
return matcher.matches();
}
}
'*' 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
偷个懒:
import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class Solution
{
public boolean isMatch(String s, String p) {
Pattern pattern = Pattern.compile(p);
Matcher matcher = pattern.matcher(s);
return matcher.matches();
}
}
相关文章推荐
- [leetcode]Regular Expression Matching
- 10、Regular Expression Matching
- Regular Expression Matching
- Regular Expression Matching
- [LeetCode] Regular Expression Matching
- [leetcode] Regular Expression Matching
- Regular Expression Matching——没理解的动态规划
- LeetCode 10: Regular Expression Matching
- 010 - Regular Expression Matching
- leetcode第10题——***Regular Expression Matching
- leetcode 10. Regular Expression Matching
- Leetcode Regular Expression Matching O(n^2) DP
- LeetCode10 Regular Expression Matching
- Leetcode: Regular Expression Matching
- leetcode----Regular Expression Matching
- LeetCode算法题目: Regular Expression Matching
- 算法设计与分析(7)-- Regular Expression Matching(难度:hard)
- [置顶] 通配符匹配(Wildcard Matching)与正则表达式匹配(Regular Expression Matching)解法解析
- [leetcode] 10 Regular Expression Matching
- LeetCode-Regular Expression Matching