zoukankan      html  css  js  c++  java
  • [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 }
  • 相关阅读:
    kafka
    yum-nginx
    expect
    ubuntu快捷方式
    10,zzlian爬取
    9-豆瓣电影
    8selenium
    7,pyquery获取数据
    6,BeautifulSoup-获取数据
    5-正则匹配获取数据
  • 原文地址:https://www.cnblogs.com/lianliang/p/5396323.html
Copyright © 2011-2022 走看看