import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?P<command>\\w{1,})(\\s?-\\s?(?P<description>.*))?";
final String string = "avvisi\n"
+ "calcola - Evaluate one or more algebric expressions\n"
+ "caratteri - Count the characters in a text message (use it in reply)\n"
+ "ciclopi - CiloPi stations status\n"
+ "coop - Get UniCoop Firenze opening hours for Pisa Cisanello shop\n"
+ "doodle - Manage doodle-type surveys\n"
+ "help - Help\n"
+ "language - Change language settings\n"
+ "monitor - Monitor a web page and notify changes\n"
+ "note - Save up to 10 notes, callable via inline query\n"
+ "ping - Check if bot is online\n"
+ "quando - Get the original sending datetime for a message (use it in reply)\n"
+ "reminder - Set a reminder\n"
+ "suggestion - Send a suggestion to help improve the bot\n"
+ "tastiera - Send a keyboard with bot commands\n"
+ "ciaone\n"
+ "ciaone - fdfdf\n"
+ "della - f";
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