aspose file tools*
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 Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "using regular expression Problem" Watch "using regular expression Problem" New topic
Author

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



output:


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 things.so,it knows all the source...
but *? operator is unwilling to do anything it prints the things in single go....it always do the easier things....*? means zero or more and it does not know about the things which will come after the current word....so,easier thing for it is to find zero.....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: using regular expression Problem