zoukankan      html  css  js  c++  java
  • 正则表达式,求判断字符串是否以数字组结尾,并取出结尾的数字 正则表达式

    import java.util.regex.*;
    
    public class Regex {
    public static void main(String[] args){
    String sa = new String("abc123");
    String sb = new String("abc123a");
    
    Pattern pattern = Pattern.compile("\d+$");
    Matcher matcher = pattern.matcher(sa);
    
    if(matcher.find()){
    System.out.println("字符串sa是以数字结尾的,结尾的数字是:"+matcher.group());
    }
    else{
    System.out.println("字符串sa不是以数字结尾的");
    }
    
    matcher.reset(sb);
    if(matcher.find()){
    System.out.println("字符串sb是以数字结尾的,结尾的数字是:"+matcher.group());
    }
    else{
    System.out.println("字符串sb不是以数字结尾的");
    }
    }
    }
    运行结果如下:
    字符串sa是以数字结尾的,结尾的数字是:123
    字符串sb不是以数字结尾的 
  • 相关阅读:
    Delphi语法
    orcad中注意的事情
    Express web框架
    Docker
    Node.JS
    再次 WebAssembly 技术探讨
    WebAssembly 浏览器中运行c/c++模块
    Http 服务 简单示例
    CentOS7 开放服务端口
    Go linux 实践4
  • 原文地址:https://www.cnblogs.com/libin6505/p/9766647.html
Copyright © 2011-2022 走看看