This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Java in General and the fly likes Help in Regex Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Help in Regex" Watch "Help in Regex" New topic
Author

Help in Regex

Frederico Benevides
Greenhorn

Joined: Jan 15, 2006
Posts: 25
I'm was studying this code



So my interest is to this the same program using Pattern, so I tried and wrote this:



My problem is that the second program, is writing with space before the words, and I don't wanna this, because in the program using scanner don't do, and I want to learn how to do the same thing using Pattern.....

So, have some one have any idea ?

Thank you.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Do you know what \\D stands for? Why would it lead to spaces being included?

Hope this helps you getting into the right direction - teaching a man to fish, and all that...


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Frederico Benevides
Greenhorn

Joined: Jan 15, 2006
Posts: 25
I know what is \D , is to get everything that is not a number...

I know will get the space too... but I don't know how to get only the words... if I choose \w+ will get the numbers too, that's my problem.

Thank you.
Alan Moore
Ranch Hand

Joined: May 06, 2004
Posts: 262
So you want to match anything that's not a digit or a whitespace character? Take a look at negated character classes. Also, there's a good regex tutorial here:

http://www.regular-expressions.info/
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Or one of the other predefined character classes, as described in the JavaDoc for the Pattern class - for example \p{Alpha}. Of course this depends on what *exactly* you want to match...
Frederico Benevides
Greenhorn

Joined: Jan 15, 2006
Posts: 25
I used \p{Alpha} worked here, and I used too [a-z]+ worked too.

Thank for the help and for the site;

[]'s Frederico.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Help in Regex
 
Similar Threads
Tokens
scanner regex question
Regex problem
Scanner class
Token Question