Saturday, 17 August 2013

ReplaceFirst with Regular Expression

ReplaceFirst with Regular Expression

Let's say i have a String
String link =
"www.thisisalink.com/tick1=@tick1@&tick2=@tick2@&tick3=@tick3@&tick4=@tick4@"
Then i can use
link = replaceFirst("(.+)=@\\1@", "");
To make it
link = "www.thisisalink.com/&tick2=@tick2@&tick3=@tick3@&tick4=@tick4@"
But i want to loop though the String, to get what has been replace and
save it somewhere else, like a linkedList or an Array... result would be:
String[] result = ["tick1=@tick1@", "tick2=@tick2@", "tick3=@tick3@",
"tick4=@tick4"]
String link = "www.thisisalink.com/&&&"
But how can i do this? I tried looping with
while (link.matches("(.+)=@\\1@")){}
which didnt work.

No comments:

Post a Comment