0

I have a string formatted as below:

source1.type1.8371-(12345)->source2.type3.3281-(38270)->source4.type2.903..

It's a path, the number in () is the weight for the edge, I tried to split it using java Pattern as following:

[a-zA-Z.0-9]+-{1}({1}\\d+){1}
[a-zA-Z_]+.[a-zA-Z_]+.(\\d)+-(\\d+)
[a-zA-Z.0-9]+-{1}({1}\\d+){1}-{1}>{1}

hopefully it split the string into fields like

source1.type1.8371-(12345)
source2.type3.3281-(38270)
..

but none of them work, it always return the whole string as the field.

1
  • 1
    i dont get it, what is expected result? and your string ends with ... ? Commented May 23, 2013 at 18:16

2 Answers 2

1

It looks like you just want String.split("->") (javadoc). This splits on the symbol -> and returns an array containing the parts between ->.

String str = "source1.type1.8371-(12345)->source2.type3.3281-(38270)->source4.type2.903..";
for(String s : str.split("->")){
    System.out.println(s);
}

Output

source1.type1.8371-(12345)
source2.type3.3281-(38270)
source4.type2.903..
Sign up to request clarification or add additional context in comments.

Comments

1

It seems to me like you want to split at the ->'s. So you could use something like str.split("->") If you were more specific about why you need this maybe we could understand why you were trying to use those complicated regexes

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.