正则表达式 匹配字母和数字
来源:互联网 发布:js如何把div隐藏 编辑:程序博客网 时间:2024/06/05 23:05
/** * *//** * @author dell * */import java.io.FileWriter;import java.io.IOException;import java.text.SimpleDateFormat;import java.util.Date;import java.util.regex.Matcher;import java.util.regex.Pattern;public class HelloWorld {/** * @param args * @throws IOException */public static void main(String[] args) throws IOException {// TODO Auto-generated method stu// String s = "is is of of";// String s="12 aa bb 好2";// String regex="(.)\\1";// String s="abcs123abc123abc123";String s = "UL8010abcd";Date date = new Date();SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");String time = df.format(date);String savedtxt = "D:\\testOK_" + time + ".txt";// String regex ="(\\d+)(\\w+)\\1";String regex = "(^UL)(\\d+)";Pattern p = Pattern.compile(regex);Matcher m = p.matcher(s);FileWriter fileWriter = null;if (m.find()) {s = m.group(0).substring(2);// s = s.substring(2);// s=Integer.parseInt(s)+"|"+123+"|"s += "|" + 123 + "|";} else {s += "|" + 123 + "|";}try {fileWriter = new FileWriter(savedtxt, true); // 加 true 等于附加,// fileWriter.write(s);fileWriter.write(s + "\r\n");// System.out.println(Integer.parseInt(s)+"|"+123+"|");System.out.println("OK");} catch (IOException ex) {ex.printStackTrace();} finally {fileWriter.flush();fileWriter.close();}}}工作中遇到一个和技术有关的导致用户不能正常使用软件的问题,只是一个正则表达式排除掉前面 的UL就可以,技术可能也没太重视,那么用户的问题就转到我这里来了,还不能解决,很是不爽。问题的解决思路大体就是这样,再将这个字符串和其它的拼接在一起就和原来 的没什么区别
//String s="abcs123abc123abc123";
String s="UL8010";
//String regex ="(\\d+)(\\w+)\\1";
String regex ="(^UL)(\\d+)";
Pattern p=Pattern.compile(regex);
Matcher m=p.matcher(s);
while(m.find()){
s=s.substring(2);
System.out.println(Integer.parseInt(s));
}
0797-2109|010791119697|郭华英|13879757233
0797-2201|UL801010294|卓喜琳|15570071192
0797-2299|UL801001967|邹明华|13763980460
0797-2299|UL801001971|郭少丽|15807977751
0797-2339|010791120440|胡声强|13479450289
阅读全文
0 0
- 正则表达式 匹配字母和数字
- 一个匹配数字和字母密码的正则表达式
- 一个匹配数字和字母密码的正则表达式
- 一个匹配数字和字母密码的正则表达式
- 一个匹配数字和字母密码的正则表达式
- 一个匹配数字和字母密码的正则表达式
- 常用的正则表达式-匹配中英文、字母和数字
- 正则表达式 基础匹配中文、数字和字母
- 史上最全的正则表达式-匹配中英文、字母和数字
- 一个匹配数字和字母密码的正则表达式
- 一个匹配数字和字母密码的正则表达式
- java正则表达式统计字母和数字
- java 字母数字和下划线 正则表达式
- 数字字母正则表达式
- 一个匹配4个数字和4个字母密码的正则表达式
- 如何匹配多个字母和数字的组合 正则表达式
- [正则表达式] 大小写字母和数字的字符匹配的实例
- 一个匹配8-16位数字和字母密码的正则表达式
- 线程池控制输出CountDownLatch同步计数器
- phabricator实战使用
- dom parser
- "Your device isn't compatible with this version" 部分设备无法从google play下载
- 去除js数组中的重复元素
- 正则表达式 匹配字母和数字
- Linux下PCI调试指令的lspci
- html中rem的基本代码
- MUI对话框
- phabricator
- 【初学】VS2013连接SQL Server 2008 R2测试
- centos7.2 ambari一键部署
- [Unity&重装系统]下载以及安装Visual Studio编程软件用来打开.cs文件
- oracle用户解锁