博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Java正则表达式例子汇总
阅读量:4700 次
发布时间:2019-06-09

本文共 1408 字,大约阅读时间需要 4 分钟。

1.过滤特殊字符

package com.sheepmu.text;  /*      * @author sheepmu  */ public class HWCompetition {	  public static void main(String[] args){		  String s="a%&a^b}b*[cc]#d{d\"ee/ff\\gg"; //!!!!!  \"是为了在字符串中转义";  \\ 只是为了在字符串中转义\		  System.out.println("原串----->"+s);		  String regex="[%{}^\\[\\]*#\\\\/&\"]";//在[ ]中,需要\\来转义[];需要\\\来转义\;\来转义"		  String news=s.replaceAll(regex,"");		  System.out.println("过滤后的串----->"+news);	  }  }
package com.sheepmu.text;  /*      * @author sheepmu  */ public class HWCompetition {	  public static void main(String[] args){		  String s="a%&a^b}b*[cc]#d{d\"ee/ff\\gg"; //!!!!!  \"是为了在字符串中转义";  \\ 只是为了在字符串中转义\		  System.out.println("原串----->"+s);		  String regex="[^%{}^\\[\\]*#\\\\/&\"]";// 在[^-----------]的第一个位置出现^表示非!!!!!!!		  String news=s.replaceAll(regex,"");		  System.out.println("过滤掉  非 特殊字符的串----->"+news);	  }  }
package com.sheepmu.text;  /*       * StringReverse(char *strIn,char *output)找出 strIn 里面所有大写字母,将其逆序输出      如输入:strIn:"abcHDLmnkKl",输出:output:"KLDH",  * @author sheepmu  */ public class HWCompetition {	  public static void main(String[] args){		  String s="abcHDLmnkKl";  		  String news=s.replaceAll("[^A-Z]","");//去掉非大写剩下的就是大写了撒~~~		   StringBuffer sb=new StringBuffer(news);//String---->StringBuffer 		   String result=sb.reverse().toString();		  System.out.println("结果----->"+ result);//KLDH	  }  }

转载于:https://www.cnblogs.com/oversea201405/p/3766897.html

你可能感兴趣的文章
【模式识别与机器学习】——SVM举例
查看>>
【转】IT名企面试:微软笔试题(1)
查看>>
IO流入门-第十章-DataInputStream_DataOutputStream
查看>>
DRF的分页
查看>>
Mysql 模糊匹配(字符串str中是否包含子字符串substr)
查看>>
python:open/文件操作
查看>>
流程控制 Day06
查看>>
Linux下安装Tomcat
查看>>
windows live writer 2012 0x80070643
查看>>
tomcat 和MySQL的安装
查看>>
git常用操作
查看>>
京东SSO单点登陆实现分析
查看>>
u-boot启动第一阶段
查看>>
MySQL批量SQL插入性能优化
查看>>
定义列属性:null,default,PK,auto_increment
查看>>
用户画像展示
查看>>
C#中StreamReader读取中文出现乱码
查看>>
使用BufferedReader的时候出现的问题
查看>>
批处理文件中的路径问题
查看>>
hibernate出现No row with the given identifier exists问题
查看>>