java - 我需要 org.sqlite.SQLiteException 的正则表达式:[SQLITE_CONSTRAINT_UNIQUE] A UNIQUE 约束失败
问题描述
我只想在“org.sqlite.SQLiteException: [SQLITE_CONSTRAINT_UNIQUE] A UNIQUE constraint failed (UNIQUE constraint failed: Items.Name)”中打印“A UNIQUE constraint failed”这条消息作为输出正则表达式的输入必需的。
解决方案
这只是匹配和之间的字符串]
,(
并且应该是一个开始。
import java.util.regex.Matcher;
import java.util.regex.Pattern;
final String regex = "\\] (.*) \\(";
final String string = "org.sqlite.SQLiteException: [SQLITE_CONSTRAINT_UNIQUE] A UNIQUE constraint failed (UNIQUE constraint failed: Items.Name)";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
推荐阅读
- java - 从 .Net Web 应用程序调用的 Java taglib
- ios - 模仿手势驱动 UIPickerview
- apache-spark - 将列从另一个数据帧附加到 pyspark 数据帧而不执行连接
- mercurial - 如何在移植期间以非交互方式处理已删除的文件“冲突”?
- ms-word - 不要在 pandoc 转换中逃避 bibtex 引用
- reactjs - 在 React 中搜索/过滤表:用空字符串替换空值
- postgresql - PostgreSQL:有没有办法创建这样的交叉表?帮忙,谢谢
- discord.py - Discord.py 临时禁令
- javascript - Javascript - 分析像素颜色差异并确定画布图像中的特征
- c# - 异步方法中的 C# 模态对话框(ShowDialog 或 MessageBox.Show)无法按预期工作