This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Regular expression Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Regular expression" Watch "Regular expression" New topic
Author

Regular expression

Mohamad Samy
Ranch Hand

Joined: Apr 26, 2013
Posts: 98
i have the following code but the regular expression don't work as i needed. i want to check the string input to be five letters only. but the code always don't respond to such condition

Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19343
    
  41

Mohamad Samy wrote:i have the following code but the regular expression don't work as i needed. i want to check the string input to be five letters only. but the code always don't respond to such condition



Can you explain to us why you believe that the regex is for five letter words?

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Jim Venolia
Ranch Hand

Joined: Sep 07, 2013
Posts: 154
    
    2

FWIW, I have a project called Toothpicks where I get my regex's working. It's nothing but the regex under development and a test harness. Much easier than getting it working in "live" code. Been doing it this way for 20 years, the toothpicks name comes from a Perl expression when dealing with the strings of \/\\\///x\/\\\/2\//\v type.

This afternoon I actually dropped down to perl so I could use it's regex debugger. Got it working quickly, but then couldn't port the silly thing to Java

It's a no-brainer. We just need to take it to the next level to turn this into a win-win situation. The best practice is to get rid of the low-hanging fruit first. Ping me with an agenda so we can go flag up on this thing
Tyson Lindner
Ranch Hand

Joined: May 16, 2012
Posts: 182
Try "\\b\\w{5}\\b" for your expression. Using "\\s" just checks for whitespaces.
 
I agree. Here's the link: http://kickstarter.com/rocket-mass-heater
 
subject: Regular expression