Regular expression in Java, a simple application example

xiaoxiao2021-03-06  62

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 (iv) {ix ((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 (}}}} catch (}}) {E.PrintStackTrace ();}}}

转载请注明原文地址:https://www.9cbs.com/read-112404.html

New Post(0)