Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/355.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/regex/20.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_Substring - Fatal编程技术网

Java中的正则表达式:查找给定子字符串集后面的数字

Java中的正则表达式:查找给定子字符串集后面的数字,java,regex,substring,Java,Regex,Substring,我有许多字符串的格式大致如下: String blah = "Blah bleh bluh Id. 24 bleh" ; String bleh = "Foo Bar Foo Id 24" ; String foo = "Blah Foo Bleh Bar Tag.93 foo" ; String bar ="Junk Jibberish Id.93" ; 其中我有一些文本,最后是一组可能的标识符(ID、ID、标识符、标记等)中的一些字符串,然后是没有空格、一个句点和一个空格、一个句

我有许多字符串的格式大致如下:

String blah =  "Blah bleh bluh Id. 24 bleh" ;

String bleh = "Foo Bar Foo Id 24" ;

String foo =  "Blah Foo Bleh Bar Tag.93 foo" ;

String bar ="Junk Jibberish Id.93" ;
其中我有一些文本,最后是一组可能的标识符(ID、ID、标识符、标记等)中的一些字符串,然后是没有空格、一个句点和一个空格、一个句点或一个空格,然后是一些数字(1-4位)和可能更多的文本

我想以“id93”或“tag93”或“id24”等格式捕获子字符串

这是一个特定的问题,我知道,但我没有一致的单个字符来分隔我试图捕获的数据

我应该遵循什么正则表达式模式?

使用正则表达式模式
\b(id | tag)\.?\s*(\d{1,4})\b
和大小写不敏感修饰符并连接组1和2



编辑:Java正则表达式格式:
\\b(id | tag)\\.?\\s*(\\d{1,4})\\b

您的意思是\\。而不是\?同时,我也发现了这些错误。。。非法转义字符:Pattern p=Pattern.compile(“\b(id | tag)\\。?\s*(\d{1,4})\b”);在\d和\b上使用Java 1。6@user1558822-在Java中,您必须用另一个\来转义每个\字符,所以使用
\\b(id | tag)\.?\\s*(\\d{1,4})\\b
而且我的编辑器给了我这个错误:无效的转义序列(有效的是\b\t\n\f\r\“\”\)为什么会这样?