正则表达式有什么应用?

科技 3年前 阅读:7 评论:0

  import java。io。*;import java。util。regex。*;public class Printer { public static void main(String[] args) { System。out。println("\nPlease enter the input string:\n"); BufferedReader reader = new BufferedReader(new InputStreamReader(System。

  in)); String inputString; boolean isOK = false; try { while(!isOK) { if((inputString = reader。readLine()) != null) { if(inputString。

  length() > 200) { System。out。println("The string exceeds 200 characters。\nPlease enter again!\n"); } else { Pattern regex = Pattern。

  compile("[^@#$%&*/^]+"); Matcher matcher = regex。matcher(inputString); boolean isMatched = matcher。matches(); if(!isMatched) { System。

  out。println("The String can't contain @,#,$,%,*,& and ^。\nPlease enter again!\n"); } else { isOK = true; System。out。println("\nYour input string is: \n" + inputString); } } } } } catch(IOException e) { e。

  printStackTrace(); } }}。

版权声明

本文仅代表作者观点,不代表木答案立场。

网友评论

本站会员尊享VIP特权,现在就加入我们吧!登录注册
登录
用户名
密码
验证码
若未跳转,可点击这里刷新重试
未知错误
注册
用户名
密码(至少8位)
确认密码
邮箱(请填写常用邮箱)
验证码
若未跳转,可点击这里刷新重试
未知错误
找回密码
用户名
邮箱
※ 重置链接将发送到邮箱
若未跳转,可点击这里刷新重试
未知错误