File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

White space regex

 
Rakoczi Markus
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1158
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try it out and see what you get. Then try and understand why you get what you get.
 
Winston Gutkowski
Bartender
Pie
Posts: 9501
50
Eclipse IDE Hibernate Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
     
    Campbell Ritchie
    Sheriff
    Pie
    Posts: 47300
    52
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Go through the Pattern class, or the Java Tutorials.
    Look for \s and *
     
    I agree. Here's the link: http://aspose.com/file-tools
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic