my dog learned polymorphism*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes scanner findInLine method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "scanner findInLine method" Watch "scanner findInLine method" New topic
Author

scanner findInLine method

Ankit Gareta
Ranch Hand

Joined: Mar 28, 2011
Posts: 67

Hi all,


I can't understand the output, actually i m confused on "s.findInLine("(\\d+) fish (\\d+) fish (\\w+) fish (\\w+)");" this line. what this line actually want to say ?

Thanks in advance.
Ankit


OCPJP 6 (91%)
Nikhil Sagar
Ranch Hand

Joined: Apr 21, 2012
Posts: 216

Ankit Gareta wrote:Hi all,


I can't understand the output, actually i m confused on "s.findInLine("(\\d+) fish (\\d+) fish (\\w+) fish (\\w+)");" this line. what this line actually want to say ?

Thanks in advance.
Ankit


In your case findInLine() says that-
Find, "(\\d+) fish (\\d+) fish (\\w+) fish (\\w+)" in String s.


OCPJP 6 86%
Ankit Gareta
Ranch Hand

Joined: Mar 28, 2011
Posts: 67

Is this "(\\d+) fish (\\d+) fish (\\w+) fish (\\w+)" String pattern doesn't return only one token where the Scanner string is "1 fish 2 fish red fish blue fish" ?
because first one or more digit then fish(2 times), then one or more words then fish...that will get in whole line.
 
Don't get me started about those stupid light bulbs.
 
subject: scanner findInLine method
 
Similar Threads
Mock question java.util.regex.Pattern - drag and drop
Scanner question or maybe it may be more about java class API's
About regex
groupcount() method in MatchResult Interface in Java 5
scanner question