我有以下代码行:
Matcher matcher = Pattern.compile("CREATE TABLE ([^ ]*) \\(").matcher("CREATE TABLE DeliveryPointAddress (");
生成的Matcher
不包含匹配项,或更重要的是,不包含表名称。
我需要更改什么才能获得组 1 中的“DeliveryPointAddress”
的匹配项?
最佳答案
我不是通灵者,但我相信你的问题是你没有调用 find()
在查询匹配器之前:
Matcher matcher = Pattern.compile("CREATE TABLE ([^ ]*) \\(").matcher(
"CREATE TABLE DeliveryPointAddress (");
matcher.find();
System.out.println(matcher.group(1));
DeliveryPointAddress
Note that find()
returns a boolean indicating whether a match was found, so normally you would do something along the lines of
if (matcher.find()) {
System.out.println(matcher.group(1));
}
但是想法是一样的:首先调用find()
!
关于java - 为了在 Java 的正则表达式中执行此操作,需要转义或进一步更改什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19062136/