Problem with simple regular expression
Pattern p = Pattern.compile("^[0-9]");
throw new RuntimeException("FOUND BAD THING");
I want to throw exception if stringTest has not only numbers, but this code always throws RuntimeException("FOUND BAD THING");
thanks, i found the solution
But what is the difference between [^0-9] and ^[0-9] ?
One works and one doesn't. Look at the Pattern class.
Originally Posted by haiaw
There is no ^[abc].
Originally Posted by Patter
particullarly there is a ^[0-9].
^ not within squared brackets and at the start of a regex means to match from beginning of input.
while the regex "abc" matches in "xxabc"
the regex "^abc" doesn't, since the pattern doesn't appear at the beginning of the input.
in square brackets ^ means negotiation.
By ac7117 in forum ASP.NET
Last Post: 01-30-2002, 05:52 PM
By Patrick Ireland in forum .NET
Last Post: 05-05-2001, 04:36 PM
Last Post: 04-13-2001, 04:31 AM
By Eric in forum Database
Last Post: 11-10-2000, 03:05 AM
By Gary Thompson in forum authorevents.kurata
Last Post: 04-20-2000, 09:13 PM
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL