Write code to check if a string contains Special Character using regex
//package com.book2s; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; public class Main { public static void main(String[] argv) { String str = "book2s.com"; System.out.println(containSpecialCharacter(str)); }/*from w ww. j av a2s. c om*/ public static boolean containSpecialCharacter(String str) throws PatternSyntaxException { String regEx = "[`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~??@#?%??&*????+|{}???????????????]"; Pattern p = Pattern.compile(regEx); Matcher m = p.matcher(str); if (m.find()) { return true; } return false; } }