This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes using regular expression Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "using regular expression Problem" Watch "using regular expression Problem" New topic

using regular expression Problem

Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

"\\w\\s*"-it finds first position Tobe a word then followed by a space


start string eend
0 0
1 1
2 2
3 3
4 4
5 5

i think output should be
start string end
0 a 2
2 1 4
4 4
5 5

why it isn't finding a followed by space as it matches (\\w\\s)*?
and 1 followed by space
then what's the use ? in the regular expression..

if i remove ? ,it finds "a 1 2"

OCPJP 6.0 93%
OCPJWCD 5.0 98%
Gari Jain
Ranch Hand

Joined: Jun 29, 2009
Posts: 100
I cannot understand the question?

What is that...a loop?

OCPJP 6-100%; Preparing for GATE11
Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

these types of question come in OCPJP.
that's why i posted it
Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

Please somebody help
i had posted the question about 3 days ago
i haven't got a correct answer

Sumit Khurana
Ranch Hand

Joined: Sep 19, 2010
Posts: 68

* is a greedy quantifier and *? is reluctant quantifier.
greedy quanitifier first go through the source and than come back and find the,it knows all the source...
but *? operator is unwilling to do anything it prints the things in single always do the easier things....*? means zero or more and it does not know about the things which will come after the current,easier thing for it is to find zero.....
Consider Paul's rocket mass heater.
subject: using regular expression Problem
Similar Threads
Regarding Regex
regex versus tokenizer
Dan's exam: Question 4, Langauage Fundamentals, Main Method
Greedy Quantifier + !!