This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
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
Sheriff
Posts: 23283
125
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
Posts: 21092
85
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
Sheriff
Posts: 23283
125
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
Boost this thread!