agent_x91
04-12-2007, 10:10 AM
This regular expression I've developed must have a slight flaw in it somewhere, so if anyone can point it out I'll be grateful. Be warned it might make your head hurt ;)
It's designed to check the format of a String command given to the LCommand object, to see if it matches various types of command. I have used very similar regular expressions which have worked 100%, but this one's not recognising it as a valid message command unless it's only given a "text" parameter.
if(s.toUpperCase().matches("^\\s*MESSAGE((\\s+((TITLW)|(COLOURS)|(BOUNDS)|(FONT))\\{((\\\\\\})*([^\\}])*)*\\})|(\\s+((RESIZABLE)|(FULLSCREEN))))*\\s+TEXT\\{((\\\\\\})*([^\\}])*)*\\}((\\s+((TITLE)|(COLOURS)|(BOUNDS)|(FONT))\\{((\\\\\\})*([^\\}])*)*\\})|(\\s+((RESIZABLE)|(FULLSCREEN))))*\\s*$"))
{
//do stuff
}
I think it may be something to do with the ((TITLE)|(COLOURS)|(BOUNDS)|(FONT)) bit which I've done slightly wrong, as I have another regex which works perfectly, and literally just replaces the four keywords with a single keyword, and replaces some other keywords. That's also included below for reference if it helps :)
f(s.toUpperCase().matches("^\\s*KILLPROCESS((\\s+FILTER\\{((\\\\\\})*([^\\}])*)*\\})|(\\s+FORCE))*\\s+NAME\\{((\\\\\\})*([^\\}])*)*\\}((\\s+FILTER\\{((\\\\\\})*([^\\}])*)*\\})|(\\s+FORCE))*\\s*$"))
{
//do stuff
}
It's designed to check the format of a String command given to the LCommand object, to see if it matches various types of command. I have used very similar regular expressions which have worked 100%, but this one's not recognising it as a valid message command unless it's only given a "text" parameter.
if(s.toUpperCase().matches("^\\s*MESSAGE((\\s+((TITLW)|(COLOURS)|(BOUNDS)|(FONT))\\{((\\\\\\})*([^\\}])*)*\\})|(\\s+((RESIZABLE)|(FULLSCREEN))))*\\s+TEXT\\{((\\\\\\})*([^\\}])*)*\\}((\\s+((TITLE)|(COLOURS)|(BOUNDS)|(FONT))\\{((\\\\\\})*([^\\}])*)*\\})|(\\s+((RESIZABLE)|(FULLSCREEN))))*\\s*$"))
{
//do stuff
}
I think it may be something to do with the ((TITLE)|(COLOURS)|(BOUNDS)|(FONT)) bit which I've done slightly wrong, as I have another regex which works perfectly, and literally just replaces the four keywords with a single keyword, and replaces some other keywords. That's also included below for reference if it helps :)
f(s.toUpperCase().matches("^\\s*KILLPROCESS((\\s+FILTER\\{((\\\\\\})*([^\\}])*)*\\})|(\\s+FORCE))*\\s+NAME\\{((\\\\\\})*([^\\}])*)*\\}((\\s+FILTER\\{((\\\\\\})*([^\\}])*)*\\})|(\\s+FORCE))*\\s*$"))
{
//do stuff
}