aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes SCJP Regex question (page:526) 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 "SCJP Regex question (page:526)" Watch "SCJP Regex question (page:526)" New topic
Author

SCJP Regex question (page:526)

Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1056


Dear Ranch,

I have query in the below code , which is mentioned in page:526 , I tried to compile it and run but the output I am getting is blank, but in the book the output answer is given option E: 01234456

Please assist.



http://www.lifesbizzare.blogspot.com || OCJP:81%
Konstantinos Alvertis
Greenhorn

Joined: May 05, 2013
Posts: 11

Dear Vishal Hegde,

Did you tried it from command line? java Regex2 '\d*" ab34ef


OCPJP6
Konstantinos Alvertis
Greenhorn

Joined: May 05, 2013
Posts: 11

Konstantinos Alvertis wrote:Dear Vishal Hegde,

Did you tried it from command line? java Regex2 "\d*" ab34ef
Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1056

Thanks its displaying false.
Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1056

But I am not getting the output 01234456
Konstantinos Alvertis
Greenhorn

Joined: May 05, 2013
Posts: 11

Dear Vishal Hegde,

You can try this: java Regex2 (\d*) ab34ef for windows works

( the double quotes  " are probably for linux , can anyone confirm this please? )
Robin Poulose
Greenhorn

Joined: May 22, 2013
Posts: 3
i am getting the following result while running in window 32bit and not in linux :

true
1234456

vishal got false may be becoz he didn't put double inverted commas!


[Thumbnail for 22-05-2013 1-02-44 PM.png]

Konstantinos Alvertis
Greenhorn

Joined: May 05, 2013
Posts: 11

Interesting!

Here i attached two screenshots of my cmd.

There is an "Known Issue" in the behaviour of Wildcard expansion here: http://www.oracle.com/technetwork/java/javase/7u4-relnotes-1575007.html

In detail:
[javadoc]Area: java command
Synopsis: Wildcard expansion behavior change on Windows platforms.

In the earlier JDK releases, a wildcard (* or ?) in double quotes on a DOS command line did not get expanded. For example, when using the following command:

java xxx "*.java"

the following string is passed to xxx:

*.java

In the current JDK release, wildcards in quoted arguments get expanded, and the matched file names (.java) are passed to xxx.

A workaround to produce the previous behavior is to escape the double quotes. For example, instead of the following command:

java xxx "*.java"

use:

java xxx \"*.java\"

Also ensure that your application code can accept both "*.java" as well as *.java as values.[/javadoc]

I use java version 7.

What java versions do you use?



[Thumbnail for regex_1.png]


[Thumbnail for regex_2.png]

Robin Poulose
Greenhorn

Joined: May 22, 2013
Posts: 3
Probably , you are correct ! its because of the versions.
Also. Why the Position 0 for the beginning of the string missing in the output for java 6 and 7?
is it a bug ?
FYI
I am using java version 6.



[Thumbnail for 23-05-2013 1-30-45 AM.png]

Konstantinos Alvertis
Greenhorn

Joined: May 05, 2013
Posts: 11

It is fine!
In the example, Vishal used find() method before the while loop! This was the first match. ( is the "true" that you printed first)
You can remove line 7 of the above code!
Here is a usefull link
http://www.coderanch.com/how-to/java/SCJP-FAQ#kb-regexp
Robin Poulose
Greenhorn

Joined: May 22, 2013
Posts: 3
opps!! thank you!!..!!didn't see it !!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SCJP Regex question (page:526)