开发者

Regular Expression and Pattern

MP (((1.1 1.2, 2.1 1.5),(3.1 4.1)),((8.1 6.2,开发者_StackOverflow 2.5 4.5),(3.8 4.9)),((7.1 6.2, 2.5 5.5),(3.8 4.9)))

In Java how i can split them to get double values. What pattern and reqex would be ? but not only doubles, with index of bracket layer

thank you.

i will appreciate if Output is like following way

bracket 1

sub bracket 1 :

point 1 :1.1 1.2

point 2 :2.1 1.5

sub bracket 2:

point 1 :3.1 4.1

bracket 2

sub bracket 1 :

point 1 :8.1 6.2

point 2 :2.5 4.5

sub bracket 2:

point 1 :3.8 4.9

...


Well, if you only want to get a list of the doubles, you can use something like this:

String input = "(((1.1 1.2, 2.1 1.5),(3.1 4.1)),((8.1 6.2, 2.5 4.5),(3.8 4.9)),((7.1 6.2, 2.5 5.5),(3.8 4.9)))";
Matcher matcher = Pattern.compile("\\d+\\.\\d+").matcher(input);
while (matcher.find()) {
    double d = Double.parseDouble(matcher.group());
    System.out.println(d);  //or alternatively, add to a list
}


I think you just need to split on any of these non-digit characters -- sounds like they don't matter at all, just the values:

value.split("[\\(\\), ]+")

Then parse each String with Double.parseDouble().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜