import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(\\((.*?)\\))";
final String string = "Chats (Felis catus)\n"
+ "Chiens (Canis lupus familiaris)\n"
+ "Chevaux (Equus ferus caballus)\n"
+ "Moutons (Ovis aries)\n"
+ "Bovins (Bos taurus taurus)\n"
+ "Porcs (Susscrofa domestica)\n"
+ "Chèvres (Capra aegagrus hircus)\n"
+ "Les lapins (Oryctolagus cuniculus)\n"
+ "Les canards (Anas platyrhyncos domesticus)\n"
+ "Les dindons (Meleagris gallopavo gallopavo)\n"
+ "Ânes (Equus asinus)\n"
+ "Mules (Equus asinus x Equus caballus)\n"
+ "Chien\n"
+ "Chat\n"
+ "Furet\n"
+ "Cheval\n"
+ "âne\n"
+ "vache\n"
+ "lama\n"
+ "mule\n"
+ "Porc\n"
+ "Cochon d'Inde\n"
+ "Rat domestique\n"
+ "Hamster doré\n"
+ "Souris domestique\n"
+ "gerbille de Mongolie\n"
+ "Lapin domestique\n"
+ "Canard colvert\n"
+ "Poule \n"
+ "paon\n"
+ "Pigeon\n"
+ "tourterelle\n"
+ "colombe\n"
+ "Canari\n"
+ "Perruche\n"
+ "Poisson rouge\n"
+ "Carpe koï\n"
+ "axolotl\n";
final String subst = "";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
// The substituted value will be contained in the result variable
final String result = matcher.replaceAll(subst);
System.out.println("Substitution result: " + result);
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html