File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Regex ??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Regex ???" Watch "Regex ???" New topic
Author

Regex ???

Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661


A 234
b 334
c 2334
d 0123456
e 01234456
f 12334567
g compilation fails

This is a Question from K&B chapter 6
The answer I got after compiling was 0.
The answer mentioned is "e is correct " even though later it says a,b,c,d,e,f,g are incorrect due to the above reason.

I believe there is a typo somewhere, but either way I cannot understand the result or the question.And i cannot understan the options given to chose the answer.They are no where even close to what i thought would be the result.

Not sure what exactly does "\d*" means.
I think it is Zero or more digits, But can somebody specify how the matching take place and also the use of group().

Thanks.


The future belongs to those who believe in the beauty of their dreams.Dream BIG!
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

This FAQ should help.


[My Blog]
All roads lead to JavaRanch
sridhar row
Ranch Hand

Joined: Jan 16, 2008
Posts: 162
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;
if (b=m.find())
System.out.println(m.start() + m.group());
}
}


Hi Nabila, If you change the if(b=m.find()) to while(b=m.find()) it should work and print 01234456.

Thanks Christopher i had the same doubt about the 6th index position

[ April 08, 2008: Message edited by: sridhar row ]
[ April 08, 2008: Message edited by: sridhar row ]
Dinesh Tahiliani
Ranch Hand

Joined: Aug 06, 2007
Posts: 486
Sridar,

Can you please expalin me the answer, how it came?



Thanks<br />Dinesh
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42950
    
  70
Did you read the FAQ entry Christophe pointed you to? It's rather detailed.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regex ???