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
Tim Cooke
paul wheaton
Ron McLeod
Jeanne Boyarsky
Sheriffs:
Paul Clapham
Saloon Keepers:
Tim Holloway
Roland Mueller
Bartenders:
Forum:
Programmer Certification (OCPJP)
Matcher and compliler problem
sharon daze
Greenhorn
Posts: 16
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hello all ,
while matching any
string
using matcher and compiler why find method always gets to the next token which do not exist in the macther argument.
See following code
package javaapplication1; import java.util.regex.*; /** * * @author Admin */ public class Example5 { public static void main(String[] args) { Pattern p = Pattern.compile("\\d*"); Matcher m = p.matcher("ab34ef88f"); boolean b= false; while(b = m.find()) { System.out.println(m.start() + " " +m.group()); } }
This code produces output like :
0
1
2 34
4
5
6 88
8
9
why i get 9 as output there no element at 9th position ?
Thanks
http://myjvm.wordpress.com
Paul Stat
Ranch Hand
Posts: 50
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
lookup greedy quantifiers
also, try splitting the output over two lines
System.out.println("Start pos: " + m.start()); System.out.println("Matched: " + m.group());
that should give you some clues
Mumtaz Khan
Ranch Hand
Posts: 53
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
check out this, it should help you understand why you are getting 9 as output.
http://faq.javaranch.com/java/ScjpFaq#kb-regexp
SCJP 5.0 -- 97%
What is that? Is that a mongol hoarde? Can we fend them off with this tiny ad?
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
greedy quantifier; find() method
Problem in regex
MetaCharacter Problem(See if you can Solve it)
Pattern Matching
doubt regarding pattern matching in java
More...