Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
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:
Java in General
Greedy quantifiers
asha ganapathy
Ranch Hand
Posts: 54
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
import java.util.regex.Pattern; import java.util.regex.Matcher; public class regex1{ 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.println(m.start()+" "+m.group()); } } }
I wrote the above code and executed this
input :
java
regex1 "\d*" "ab34ef"
output: 01234456
input : java regex1 "\d?" "ab34ef"
output: 012334456
I did not understand why the output gives the index 6 when there are elements only from 0-5?
Bert Bates
author
Posts: 9050
21
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hey Asha -
I'm going to move this to the intermediate forum. If you're studying for the
SCJP
, then let us know and we'll move it to that forum instead
Bert
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
asha ganapathy
Ranch Hand
Posts: 54
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi Bert,
Wow!!
Great to see you in the forum.
Yes i am preparing for SCJP exam
Thanks,
Asha
Forget Steve. Look at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
doubt regarding patterns in regex
Regex Program
Puzzled by RegEx match and pattern (K&B) Chapter 6: Question: 1
Regex help
Greedy quantifiers
More...