Trying to work on a regular expression that will make this little process easier for me to handle data while giving a rather basic string-based scripting interface. The Intent is to allow a user to affect the interaction of certain objects based on their default interaction. Please note, this may be Minecraft based, but the question is strictly limited to Java as the community for Minecraft coding would be far less valuable.
Code:
"!if '100' == '100' rblk CakeTown 217 67 -22 0|heal Komak57" should equate to {"!if","100","==","100","rblk CakeTown 217 67 -22 0","heal Komak57"}
"!if" has already been determined and will be constant. the apostrophes suggest variable 1 (which is typically non-spaced, but it's best to allow for spaces just in case) then the eq check, another variable with apostrophes to match boundries, a command which may have any characters except semi-colon, ended by a break character "|" followed by another set of digits containing any characters except a semicolon followed by the end of the string.
"(!if) '(\\.*)' (\\.\\.) '(\\.*)' (\\.*)|(\\.*)" is the best way i can represent it? I just fail horribly at regex =.= help is much appreciated?
Code:
// !if 'val' eq 'val' command|elsecommand
String com = "!if '100' == '100' rblk CakeTown 217 67 -22 0|heal Komak57";
String regex = "";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(com);
List<String> matches = new ArrayList<String>();
while (m.find()) {
matches.add(m.group());
}
msg = "Teleporter: Script command: (" + matches.size() + ") ";
for (int t = 0; t < matches.size(); t++) {
if (t == 1) {
msg = msg + "[" + matches.get(t) + "]";
} else {
msg = msg + " [" + matches.get(t) + "]";
}
}
"!if '100' == '100' rblk CakeTown 217 67 -22 0|heal Komak57" should equate to {"!if","100","==","100","rblk CakeTown 217 67 -22 0","heal Komak57"}
"!if" has already been determined and will be constant. the apostrophes suggest variable 1 (which is typically non-spaced, but it's best to allow for spaces just in case) then the eq check, another variable with apostrophes to match boundries, a command which may have any characters except semi-colon, ended by a break character "|" followed by another set of digits containing any characters except a semicolon followed by the end of the string.
"(!if) '(\\.*)' (\\.\\.) '(\\.*)' (\\.*)|(\\.*)" is the best way i can represent it? I just fail horribly at regex =.= help is much appreciated?