I would like to do pattern matching for following text in my word file, I am not sure how I can use pattern matcher
(P // TRIF) (P) (U//TRIF) (U)
import java.util.ArrayList;
import java.util.List;
import java.util.regex;
public class ExtractDemo {
public static void main(String[] args) {
String input = "I have a ( U) but I (P) like my (P//TRIF) better (U//TRIF).";
Pattern p = Pattern.compile("(P|U|P//TRIF|U//TRIF)");
Matcher m = p.matcher(input);
List<String> animals = new ArrayList<String>();
while (m.find()) {
System.out.println("Found a " + m.group() + ".");
animals.add(m.group());
}
}
}
Aucun commentaire:
Enregistrer un commentaire