aspose file tools*
The moose likes Java in General and the fly likes A simple RegEx just doesn't make sense... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "A simple RegEx just doesn Watch "A simple RegEx just doesn New topic
Author

A simple RegEx just doesn't make sense...

Kevin P Smith
Ranch Hand

Joined: Feb 18, 2005
Posts: 362
Hi,

Just wondering if someone could explain the obvious issue with the below regEx and why is does NOT allow numbers...

"^[A-Za-z0-9 ]{3,50}$"

A couple of simple tests both of which I would expect to be OK, but test 2 fails:-

Test 1: "This is a string" = OK
Test 2: "This is a string 123" = NOT OK

Cheers in advance
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18999
    
  40

Kev Bellion wrote:
Just wondering if someone could explain the obvious issue with the below regEx and why is does NOT allow numbers...

"^[A-Za-z0-9 ]{3,50}$"

A couple of simple tests both of which I would expect to be OK, but test 2 fails:-

Test 1: "This is a string" = OK
Test 2: "This is a string 123" = NOT OK

Cheers in advance


What you describe doesn't make sense. Can you post some code that shows this ?

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

Both succeed for me:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Kevin P Smith
Ranch Hand

Joined: Feb 18, 2005
Posts: 362
Henry Wong wrote:
Kev Bellion wrote:
Just wondering if someone could explain the obvious issue with the below regEx and why is does NOT allow numbers...

"^[A-Za-z0-9 ]{3,50}$"

A couple of simple tests both of which I would expect to be OK, but test 2 fails:-

Test 1: "This is a string" = OK
Test 2: "This is a string 123" = NOT OK

Cheers in advance


What you describe doesn't make sense. Can you post some code that shows this ?

Henry


Basically...
Kevin P Smith
Ranch Hand

Joined: Feb 18, 2005
Posts: 362
Rob Spoor wrote:Both succeed for me:


Yes, OK Eclipse is c--p!
Tried your example above and it worked for me too, which I'd expect as the RegEx (as far as I know) is correct.
Done a complete clean of my project in Eclipse and clean deploy (where it wipes your entire old app and re-deploys to the server rather than a standard deploy that just replaces file that have changed) and what you know, it works!!!
So it was some sort of Eclipse issue, not a code issue.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18999
    
  40

Glad you figured it out -- as I was about to report that it works for me too.
 
 
subject: A simple RegEx just doesn't make sense...