Re: check string for different criteria
- From: Roland <roland@xxxxxxxxx>
- Date: Fri, 27 May 2005 18:04:50 +0200
On 27-5-2005 17:08, Frank Meyer wrote:
Hi newsgroup,
not only that I have some trouble with my ArrayLists, I also need to check Strings.
The problem is that I will have to check around 100 string if they meet the specific criteria as follows:
XXX-000000
which means they have to start with three capital letters followed by a hyphen and a six-digit number.
If anyone knows anything, I would be really thankful.
Once again best regards
Frank
Use a regular expression: [A-Z]{3}-\d{6}In a Java string literal you have to escape the backslash, so this would become
if ( Pattern.matches("[A-Z]{3}-\\d{6}", theStringToCheck) ) {
// accepted
} else {
// rejected
}<http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html> -- Regards,
Roland de Ruiter ___ ___ /__/ w_/ /__/ / \ /_/ / \ .
- Follow-Ups:
- Re: check string for different criteria
- From: Frank Meyer
- Re: check string for different criteria
- References:
- check string for different criteria
- From: Frank Meyer
- check string for different criteria
- Prev by Date: check string for different criteria
- Next by Date: Re: return more than one object within one method
- Previous by thread: check string for different criteria
- Next by thread: Re: check string for different criteria
- Index(es):
Relevant Pages
|