I am trying to match and capture the command and parameters from the following input:
!command param1 param2
I am using Java's classes Pattern
and Matcher
:
private Pattern regExp = Pattern.compile(
"^!(?<command>[^\\s]*)((?:\\s+)(?<param>[^\\s]*))*$");
public String command() {
m = regExp.matcher(getMsg());
return m.matches() ? m.group("command") : "";
}
public String param(int index) {
return m.group(index);
}
also using this (http://fiddle.re/yanta6) to experiment ....
some pointer and help appreciated!