import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^\\[(\\w+)\\]$";
final String string = "[abilities]\n"
+ "UnknownName = ??? Ability\n"
+ "UnknownDescFun0 = No description.\n"
+ "UnknownDescTech0 = This ability does not seem to have any purpose.\n\n"
+ "OneHitDeathName = 1-Hit Hero Badge\n"
+ "OneHitDeathDesc0 = You die in one hit. Only for the brave!\n\n"
+ "AddElement = Test Text.\n\n"
+ "SuckInOrbsName = Item Magnet Badge\n"
+ "SuckInOrbsFun0 = Item just out of reach? No longer a problem!\n"
+ "SuckInOrbsTech0 = Automatically attract nearby collectibles!\"\n\n"
+ "[spac_eship]\n"
+ "[spac_eship]hub_alert_generic0 = …\n"
+ "hub_alert_generic1 = [icon:trophy][trophy]今年度鳥映画アワード[/trophy]は内部の者によって不正に染まっていた。\n";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
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