首页 > 编程语言 >java正则表达式不包含特殊字符验证

java正则表达式不包含特殊字符验证

时间:2023-02-01 12:44:06浏览次数:37  
标签:regex java String 正则表达式 Pattern str public 特殊字符

原文链接:https://blog.csdn.net/weixin_39625782/article/details/114674258

package com.sodii.regex.demo;

import java.util.regex.Matcher;

import java.util.regex.Pattern;

public class RegexDemo {

/**@author wtmax

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

RegexDemo rd=new RegexDemo();

rd.testRegex();

rd.testRegex2();

}

public void testRegex(){

String str="ww%%%qq%%q";

//不包含%的任何一个字符

//String regex="[^%]";

//不包含%的任何字符串

String regex="[^%]{1,}";

Pattern p=Pattern.compile(regex);

Matcher m=p.matcher(str);

System.out.println(m.matches());

}

public void testRegex2(){

String str="wwqqqs
$fd
$fd
w";

//不包含%,&,$的任何字符串 // <>/!@#$%^&*()

String regex="[^%$&]{1,}";

Pattern p=Pattern.compile(regex);

Matcher m=p.matcher(str);

System.out.println(m.matches());

}

}

标签:regex,java,String,正则表达式,Pattern,str,public,特殊字符
From: https://www.cnblogs.com/fswhq/p/16981421.html

相关文章