Would something like this get you going?
import java.util.ArrayList;
import java.util.Arrays;
public class MyClass {
public static void main(String args[]) {
// Assume all data is dates
String dates[] = {"25/11/1995", "26/11/1995", "27/11/1995", "28/11/1995","29/11/1995"};
// Determine the delimeter
String delimeter = String.valueOf(dates[0].replaceAll("\\d", "").charAt(0));
// Separate out the days, months, and years distictively
ArrayList<String> days = new ArrayList<String>();
ArrayList<String> months = new ArrayList<String>();
ArrayList<String> years = new ArrayList<String>();
for (String date : dates) {
String[] pieces = date.split(delimeter);
if (!days.contains(pieces[0])) {
days.add(pieces[0]);
}
if (!months.contains(pieces[1])) {
months.add(pieces[1]);
}
if (!years.contains(pieces[2])) {
years.add(pieces[2]);
}
}
// Generate regex
System.out.print((days.size() > 1) ? "(" + String.join("|", days) + ")" : days.get(0));
System.out.print(delimeter.contentEquals("/") ? "\\" + delimeter : delimeter);
System.out.print((months.size() > 1) ? "(" + String.join("|", months) + ")" : months.get(0));
System.out.print(delimeter.contentEquals("/") ? "\\" + delimeter : delimeter);
System.out.print((years.size() > 1) ? "(" + String.join("|", years) + ")" : years.get(0));
}
}
Result:
(25|26|27|28|29)\/11\/1995
I know it's not giving the exact regex you posted in your question, but it is a valid regular expression.
I tested it at Regex101
To get exactly what you're wanting, just make the generating of the regex smarter to recognize sequences.