import java.util.regex.*;
public class RegexString {
public static void main( String args[] ){
// String to be scanned to find the pattern.
String line = "control.avgo: 29 50.49854 50.504984 50000 50.5000001 0.0 1 2"
String pattern = "()()()()()()()()";
// Create a Pattern object
Pattern r = Pattern.compile(pattern);
// Now create matcher object.
Matcher m = r.matcher(line);
if (m.find( )) {
System.out.println("Found value group 0: " + m.group(0) );
System.out.println("Found value group 1: " + m.group(1) );
System.out.println("Found value group 2: " + m.group(2) );
System.out.println("Found value group 3: " + m.group(3) );
System.out.println("Found value group 4: " + m.group(4) );
System.out.println("Found value group 5: " + m.group(5) );
System.out.println("Found value group 6: " + m.group(6) );
System.out.println("Found value group 7: " + m.group(7) );
} else {
System.out.println("Pattern is no good!");
}
}
}
大家好!
以上是我在正则表达式上找到的一个简单示例,我的目标是构建一个正则表达式模式来提取每个整数和双精度数并将其放在每个组中。到目前为止,我的研究只能得到整数,我不知道如何提取每个 int 的双精度并将它们放入每个组中?!?我理解分组概念,因此 ()()()()().... 查看空格并提取其中的数字会更容易还是可以 (int)(double)(double)(int) (double)(int)(int) 表达式是精心制作的?