Java 正则表达式匹配[WORD]:[number][number][number]
我对Regex还很陌生,我从来都不会对这些东西耿耿于怀。 “字:21.889236 21.889236 0” 我试图检索单词和3个数字的完整形式,所有小数保持不变。这也将在多次出现的文件中运行。 也会有这样的台词 “WORD:1.0 1.0”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
这给了我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