Q:

How to get N random string from a {a1|a2|a3} format string?

Take this string as input:
string s1="planets {Sun|Mercury|Venus|Earth|Mars|Jupiter|Saturn|Uranus|Neptune}{?|!|.}"
string s2="some text {morning,night,evening} some text{?|!|.}"

How would I choose randomly N from the set, then join them with comma. The set is defined between {} and options are separated with | pipe
The order is maintained. String can have multiple sets {}.
Some output could be:
string output1="planets Sun, Venus.";
string output2="planets Neptune!";
string output3="planets Earth, Saturn, Uranus, Neptune.";
string output4="planets Uranus, Saturn.";// bad example, order is not correct
string output5="some text morning!";

Java 1.5

A:

Stick the planets into an array, and remove random elements until you have enough. There are cuter solutions, algorithmically speaking, but for the amount of data you're dealing with, this is quick and simple.

