- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我在我的项目中将其作为单元测试运行
public class RadioTest {
private static Pattern tier;
private static Pattern frequency;
private static Pattern state;
static {
tier = Pattern.compile("Tier: \\d");
frequency = Pattern.compile("Frequency: \\d{3}");
state = Pattern.compile("State: (OFF|ON)");
}
@Test
public void test() {
String title = "Tier: 2";
String title2 = "Frequency: 135";
String title3 = "State: ON";
assertTrue(tier.matcher(title).matches());
assertTrue(frequency.matcher(title2).matches());
assertTrue(state.matcher(title3).matches());
Matcher m = tier.matcher(title);
System.out.println(m.find());
System.out.println(m.group(1));
}
}
但是我得到一个错误 IndexOutOfBoundsException: No group 1
我知道这与 m.group(1)
有关,但有什么问题吗?在控制台中,我还从 m.find()
中看到了 true
。我搜索了如何使用正则表达式,但它表明可以这样做。
最佳答案
Pattern.compile("Tier: \\d");
没有定义一个组所以这个表达式匹配但是你不能提取一个组。您可能希望这样做:
Pattern.compile("Tier: (\\d)");
还有你的其他表情。您需要 ()
将要提取为组的部分括起来。
关于Java 正则表达式错误 - 没有第 1 组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32281733/
我正在使用 Gunicorn 为 Django 应用程序提供服务,它工作正常,直到我将其超时时间从 30 秒更改为 900000 秒,我不得不这样做,因为我有一个用例需要上传和处理一个巨大的文件(过程
我有一个带有非常基本的管道的Jenkinsfile,它可以旋转docker容器: pipeline { agent { dockerfile { args '-u root' } } stag
在学习 MEAN 堆栈的过程中,我遇到了一个问题。每当我尝试使用 Passport 验证方法时,它都不会返回任何响应。我总是收到“localhost没有发送任何数据。ERR_EMPTY_RESPONS
在当今的大多数企业堆栈中,数据库是我们存储所有秘密的地方。它是安全屋,是待命室,也是用于存储可能非常私密或极具价值的物品的集散地。对于依赖它的数据库管理员、程序员和DevOps团队来说,保护它免受所
是否可以创建像图片上那样的边框?只需使用 css 边框属性。最终结果将是没 Angular 盒子。我不想添加额外的 html 元素。我只想为每个 li 元素添加 css 边框信息。 假设这是一个 ul
我是一名优秀的程序员,十分优秀!