wood burning stoves 2.0*
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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: scanner findInLine method