Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Kevin P Smith
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21510
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rob Spoor
Sheriff
Pie
Posts: 20669
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both succeed for me:
 
Kevin P Smith
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21510
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad you figured it out -- as I was about to report that it works for me too.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic