Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Programmer Certification (OCPJP)
Regex Doubt
Lata Bagga
Ranch Hand
Posts: 35
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hello Friends,
I have doubt in the following regex question:
import java.util.regex.*; class Regex2 { public static void main(String[] args) { Pattern p = Pattern.compile(args[0]); Matcher m = p.matcher(args[1]); boolean b = false; while(b = m.find()) { System.out.print(m.start() + m.group()); } } } And the command line: java Regex2 "\d*" ab34ef What is the result? A. 234 B. 334 C. 2334 D. 0123456 E. 01234456 F. 12334567 G. Compilation fails.
Answer is E i.e. 01234456.
But what I think the answer should be 0123445 instead of 01234456. Can anyone explain me why in the output we are having an extra 6?
Regards,
Lata
Ulf Dittmer
Rancher
Posts: 43081
77
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Please
SearchFirst
(and
QuoteYourSources
, actually).
This is asked so often that is has its own FAQ entry:
http://faq.javaranch.com/java/ScjpFaq#kb-regexp
Lata Bagga
Ranch Hand
Posts: 35
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thanks a lot!!
Arch enemy? I mean, I don't like you, but I don't think you qualify as "arch enemy". Here, try this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Doubt in question 1 chapter 6 of K&B SCJP 5 Study Guide
Regex Doubt
Doubt about Regular Expression
K&B doubt --> Parsing
Regex Self Test doubt
More...