troubleshooting Question

Greedy Quantifier * and + in Java

Avatar of techbro
techbroFlag for United States of America asked on
10 Comments3 Solutions530 ViewsLast Modified:
I am learning how the greedy quantifiers work, but I am not getting the result I am expecting from the code below, with this argument given (Notice I am using *, dot and + quantifiers):

Possible Arguments:
C.*L  "CooLooLCuuLooC"
C.+L  "CooLooLCuuLooC"

I like to know why the result comes as 0 "CooLooLCuuL" in both of those arguments instead of:
0 CooL 6 LC 10  CooL

import java.util.regex.*;
public class TestClass
	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()+" \"""\" ");

Open in new window

I will appreciate your response.
Join our community to see this answer!
Unlock 3 Answers and 10 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 10 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros