fork download
  1. import java.util.ArrayList;
  2. import java.util.List;
  3. import java.util.regex.Matcher;
  4. import java.util.regex.Pattern;
  5.  
  6. public class Main {
  7. public static final Pattern PATTERN = Pattern.compile("\\[\\s*\\*\\s*(.*?)\\s*?\\*\\s*\\]");
  8.  
  9. public static List<String> parse(String fileContent) {
  10. Matcher matcher = PATTERN.matcher(fileContent);
  11. List<String> foundData = new ArrayList<>();
  12. while (matcher.find()) {
  13. foundData.add(matcher.group(1));
  14. }
  15. return foundData;
  16. }
  17.  
  18. public static void printOutList(List<? extends CharSequence> list) {
  19. list.forEach(System.out::println);
  20. }
  21.  
  22. public static void main(String[] args) {
  23. printOutList(parse("[ this will not match ] [ * YOU WILL BE MATCHED!!!11 * ] [* you as well *] [*you too*]" +
  24. " [ * this as well *] [this * will * not]"));
  25. }
  26. }
Success #stdin #stdout 0.2s 320768KB
stdin
Standard input is empty
stdout
YOU WILL BE MATCHED!!!11
you as well
you too
this as well