Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/331.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,我有一根绳子 1,11,cda74944-1c61-4325-8137-83a4ab50cb81-A00123,Bs000000216,20140204185143.811 能否提供正则表达式或java字符串函数来获取子字符串: cda74944-1c61-4325-8137-83a4ab50cb81-A00123?如果有这样的字符串,请使用模式: /\w{8}-\w{4}-\w{4}-\w{4}-\w{12}-\w{6}/ 模式是: [a-f0-9]++(?>-[a-z0-9]++

我有一根绳子

1,11,cda74944-1c61-4325-8137-83a4ab50cb81-A00123,Bs000000216,20140204185143.811 
能否提供正则表达式或java字符串函数来获取子字符串:


cda74944-1c61-4325-8137-83a4ab50cb81-A00123?

如果有这样的字符串,请使用模式:

/\w{8}-\w{4}-\w{4}-\w{4}-\w{12}-\w{6}/
模式是:

[a-f0-9]++(?>-[a-z0-9]++)+
您可以拆分字符串:

String[] array = String.split(",");
这将返回如下所示的字符串数组

["1", "11", "cda74944-1c61-4325-8137-83a4ab50cb81-A00123", "Bs000000216", "20140204185143.811"]

您可以在数组[2]中访问所需的部分。

您可以拆分字符串

String[] allStrings= String.split(",");
then try to get allStrings[2]  //it will give you the desired result  cda74944-1c61-4325-8137-83a4ab50cb81-A00123
有几个选择:

使用长度:

String s = yourString.subString(0, yourString.length() >>> 1);
使用拆分:

String s = yourString.split(",")[2];

或者,如果您有一些表示物理数据的内容总是以类似的方式表示,那么将其封装在类中可能会更明智。

这部分内容总是第三部分吗?1输入的规则是什么。你先试了什么?