Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 随机字母/符号的正则表达式_Java_Regex - Fatal编程技术网

Java 随机字母/符号的正则表达式

Java 随机字母/符号的正则表达式,java,regex,Java,Regex,我已经用正则表达式生成器和检查器搜索了几个小时,但我似乎无法让它工作 我有这个字符串:hdr;cr92;cl3,,442070250,此处为随机消息;etr 到目前为止,我的代码是: private void strchecker() { Pattern pattern = Pattern.compile("(\\d{9})"); Matcher matcher = pattern.matcher(strLine); if (matcher.find()) {

我已经用正则表达式生成器和检查器搜索了几个小时,但我似乎无法让它工作

我有这个字符串:hdr;cr92;cl3,,442070250,此处为随机消息;etr

到目前为止,我的代码是:

private void strchecker() {

    Pattern pattern = Pattern.compile("(\\d{9})");
    Matcher matcher = pattern.matcher(strLine);
    if (matcher.find()) {
        System.out.println(matcher.group(0)); //prints /{item}/
    } else {
        //System.out.println("Match not found");
    }

}
此代码正在工作,它在字符串中查找9位数字。我要做的是找到正则表达式代码来搜索cl3或cl2,如果它存在,那么将9位数字发送到一个变量。我只是不知道如何找到cl3或CL2

有什么建议吗

谢谢
Matt

既然你注意到你在使用javascript,我想你可以这样做,因为你不能使用Lookback;你只需要抓住捕获组,而不是使用完整的匹配

cl\\([23].*?(\\d{9})

最后的括号将捕获第1组中的9位数字。

您不能只使用cl\\\\d?太好了!找到了cl,但我需要它2或3,但不是1cl\\[23]?怎么样?:youvee让我开心!花了我几个小时的时间,你只花了不到一分钟。我想我得多学点正则表达式。。。我要去试着找出剩下的代码:D谢谢!谢谢你的帮助!但是我使用的是javascript:pHi,不起作用:有没有办法把它转换成javascript?你说它不起作用是什么意思?这对我来说似乎很好……”hdr;cr92;cl3,,442070250,此处为随机消息;etr;'。match/cl\[23].\d{9}/[1]-您甚至可以在浏览器的控制台中执行此操作。我使用了完全相同的代码,但在eclipse中,它说无效的转义序列有效的转义序列是\b\t\n\f\r\\\\\@user2078674我明白您的意思是java,而不是JavaScript。差别很大!您需要转义反斜杠类型\\d
/cl\([23].*(\d{9})/