正则表达式匹配[WORD]:[数字] [数字] [数字]

问题描述:

我是RegExs的新手,我永远无法将这些东西包裹起来。 “WORD:21.889236 21.889236 0” 我试图检索WORD和3个数字以后的完整形式,所有小数完好无损。这也将通过多次出现的文件。 也将有这样 行 “词:1.0 1.0 0”正则表达式匹配[WORD]:[数字] [数字] [数字]

(\\w+):.([\\d[0-9].{8}).(\\d[0-9].{6})..(\\d[0-9]) 

这让我在Eclipse中的错误。

+1

尝试测试:// regex101。 com /。 – shoover

+1

这个正则表达式有更多的错误。也许你应该从阅读教程开始? – Biffen

你可以使用这个表达式:

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

在Java中使用:

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

RegEx Demo

破碎:在HTTPS

\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