1、匹配括号内的内容
Matcher str = Pattern.compile("(?<=\\()(\\S+)(?=\\))").matcher(items[which]);
if (str.find()){
Device device = ManageRepository.getDevice(str.group(1));
}
2、匹配类似8618839127021_info.zip 这样的文件名
fileName.matches("^[0-9]{8,13}_info(\\.zip)$")
3、切割句子,用如: (24)- 来切割句子
String[] values = Pattern.compile("\\([0-9]*\\)-").split(messageObject.caption.toString());
4、匹配有效手机号
给定一个包含电话号码列表(一行一个电话号码)的文本文件 file.txt,写一个 bash 脚本输出所有有效的电话号码。假设一个有效的电话号码必须满足以下两种格式: (xxx) xxx-xxxx 或 xxx-xxx-xxxx。(x 表示一个数字)
grep -P "^(\d{3}-){2}\d{4}$|^\(\d{3}\)\s\d{3}-\d{4}$" file.txt
一直补充…