1         String a = "1991\12\16";
2 String[] split = a.split("\\");
3 System.out.println(new Gson().toJson(split));

报错java.util.regex.PatternSyntaxException: Unexpected internal error near index 1 \  ^

报这个错的原因是因为在java中“\”是一个转义字符,所以需要用两个"\"代表一个。例如

System.out.println("\\");只会打印出一个\,但是“\”也是正则表达式中的转移字符在java中split的参数就是正则表达式,所以需要用两个"\"代表一个,所以:\\\\被java转换成\\又被正则转换成\

另外 replaceAll,split等java方法中的参数都是正则表达式,如果是\的话都需要写\\\\

随机推荐

  1. lightoj 1020 (博弈)

    思路:很简单的博弈,找出每个人先拿的必胜态进行状态转移即可. #include<cstdio> #include<string> #include<cstring> ...

  2. 交易策略研究 R库

    本文在Creative Commons许可证下发布 交易策略研究 R库,直接安装:xts, TTR,quantmod,RTAQ,PerformanceAnalytics,FactorAnalytics ...

  3. Bzoj 4591: [Shoi2015]超能粒子炮·改 数论,Lucas定理,排列组合

    4591: [Shoi2015]超能粒子炮·改 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 178  Solved: 70[Submit][Stat ...

  4. Code First 更新数据库结构

    参考:http://blog.csdn.net/sxycxwb/article/details/12186159 0.删除之前的数据库 1.Run the Enable-Migrations comm ...

  5. grails2.3.11第一课

    以指令的方式Getting Started 1. 创建一个项目 grails create-app HelloGrails 2. 因为我环境变量中配置的jdk是1.8的,所以我要把这个项目搞到IDEA ...

  6. A Tour of Go Exercise: Maps

    Implement WordCount. It should return a map of the counts of each “word” in the string s. The wc.Tes ...

  7. 传统XmlDocument操作

    需要引用的命名空间: using System.Xml; 常用的类:XmlDocument.XmlElement.XmlNode.XmlNodeList 一.使用XmlDocument创建xml // ...

  8. C#- 将秒数转化成任意时间格式

    将秒数转化成任意时间格式,可以使用C#的一个函数TimeSpan,看示例: TimeSpan ts = new TimeSpan(0, 0, 3661); richTextBox2.Text = ts ...

  9. charindex的用法

    declare @str nvarchar(50);set @str='462,464,2';select @str as '字符串'select len(@str) as '字符长度' select ...

  10. MySQL 常用语句 (汇集)

    原文地址:MySql常用语句作者:wuyanle 一.mysql常用语句 创建,删除和最基本查询: 显示数据库  mysql->show databases; 创建数据库  mysql-> ...