On Jul 16, 2004, at 7:21, [EMAIL PROTECTED] wrote:
I want to validate an attribute, the rule is that the input should
not start with 'Test',
how to write the regular expression for this validation. Please help me
guys.
If you validate by code you can negate that it does start that way:
// pseudocode if (!(attr matches ^Test\b)) { ... }
As you surely know, the \b asserts that the word finishes there, so we don't match "Testosterone".
In a config file one cannot put that ! operator. In that case use a negative look-ahead assertion:
# in config file regexp = ^(?!Test\b)
// in Java, unconditionally test for a match if (attr matches regexp) { ... }
The (?!...) syntax is Perl's. I don't remember if Java libraries use the same one though is likely, you could double-check it ("negative look-ahead assertion" is the keyword to search for).
There's a more convoluted way to do that if one does not have assertions:
# untested, but you get the idea regexp = "^([^T]|T([^e]|e([^s]|s([^t]|t\B))))
But as you see assertions are more concise and readable for that.
-- fxn
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]