Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/379.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 正则表达式匹配[WORD]:[number][number][number]_Java_Regex - Fatal编程技术网

Java 正则表达式匹配[WORD]:[number][number][number]

Java 正则表达式匹配[WORD]:[number][number][number],java,regex,Java,Regex,我对Regex还很陌生,我从来都不会对这些东西耿耿于怀。 “字:21.889236 21.889236 0” 我试图检索单词和3个数字的完整形式,所有小数保持不变。这也将在多次出现的文件中运行。 也会有这样的台词 “WORD:1.0 1.0” 这给了我eclipse内部的一个错误。您可以使用以下正则表达式: \b(\w+):\s*(?:\d+(?:.\d+)?\s*){3} 在Java使用中: "\b(\w+):\\s*(?:\\d+(?:.\\d+)?\\s*){3}" 分手: \b

我对Regex还很陌生,我从来都不会对这些东西耿耿于怀。 “字:21.889236 21.889236 0” 我试图检索单词和3个数字的完整形式,所有小数保持不变。这也将在多次出现的文件中运行。 也会有这样的台词 “WORD:1.0 1.0”


这给了我eclipse内部的一个错误。

您可以使用以下正则表达式:

\b(\w+):\s*(?:\d+(?:.\d+)?\s*){3}
在Java使用中:

"\b(\w+):\\s*(?:\\d+(?:.\\d+)?\\s*){3}"

分手:

\b          # word boundary
(\w+)       # match a word
:           # match literal :
\s*         # match 0 or more white-spaces
(?:         # start non-capturing group 1
   \d+      # match 1 or more digits
   (?:      # start non-capturing group 2
      .     # match a decimal point
      \d+   # match 1 or digits
   )?       # end non-capturing group 2 and make it optional
   \s*      # match 0 or more white-spaces
){3}        # end non-capturing group 2 and repeat it 3 times

试着测试一下,这个正则表达式错的比对的多。也许你应该从阅读教程开始?
\b          # word boundary
(\w+)       # match a word
:           # match literal :
\s*         # match 0 or more white-spaces
(?:         # start non-capturing group 1
   \d+      # match 1 or more digits
   (?:      # start non-capturing group 2
      .     # match a decimal point
      \d+   # match 1 or digits
   )?       # end non-capturing group 2 and make it optional
   \s*      # match 0 or more white-spaces
){3}        # end non-capturing group 2 and repeat it 3 times