fork download
  1. import java.util.regex.Matcher;
  2. import java.util.regex.Pattern;
  3.  
  4. class Ideone {
  5. public static void main(String[] args) {
  6. String teamPattern = "[MW3-%s]";
  7. String teamName = "apple";
  8. String fullNamePattern = "full name: " + teamPattern;
  9. String fullName = String.format(fullNamePattern, teamName);
  10. Pattern teamExtractorPattern = Pattern.compile("^full name: \\[MW3-(?<teamName>.*)]$");
  11. Matcher matcher = teamExtractorPattern.matcher(fullName);
  12. if (matcher.matches()) {
  13. String extractedTeamName = matcher.group("teamName");
  14. System.out.println(extractedTeamName);
  15. }
  16. }
  17. }
Success #stdin #stdout 0.17s 50720KB
stdin
Standard input is empty
stdout
apple