| Author |
White space regex
|
Rakoczi Markus
Greenhorn
Joined: Mar 13, 2012
Posts: 13
|
|
Hello
I not experienced with regex expresions, and i want to check if a textfield contains white spaces, so i read the textfield content and matches with a regex expression
for example:
is my regex expression complete enough to check for any posibile white space content?
Thanks.
|
 |
Mansukhdeep Thind
Ranch Hand
Joined: Jul 27, 2010
Posts: 1142
|
|
Try it out and see what you get. Then try and understand why you get what you get.
|
~ Mansukh
|
 |
Winston Gutkowski
Bartender
Joined: Mar 17, 2011
Posts: 4739
|
|
Rakoczi Markus wrote:I not experienced with regex expresions, and i want to check if a textfield contains white spaces, so i read the textfield content and matches with a regex expression
Well, first: Do you want to know if the field contains ANY whitespace or if it contains ONLY whitespace?
Because:
1. You should look up the API documentation for String.matches(), and make sure that it's really what you want. 2. '*' means "0 or more"; and that '0' is very important.
You should probably also look at the java.util.regex.Pattern and java.util.regex.Matcher classes.
There's a fair bit to know about regexes, and you can't learn it overnight.
Winston
|
Isn't it funny how there's always time and money enough to do it WRONG?
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32651
|
|
Go through the Pattern class, or the Java Tutorials.
Look for \s and *
|
 |
 |
|
|
subject: White space regex
|
|
|