About Question enthuware.ocpjp.v7.2.1180 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
ETS User

About Question enthuware.ocpjp.v7.2.1180 :

Post by ETS User »

Hey,

The explanation by the second answer sounds wrong. If I understand it correctly, the explanation says basicly the regex is

Code: Select all

o\\b
, while it is

Code: Select all

\\bo
What indeed would result in the second answer.
If it is the regex how the explanation says, the explanation is at the wrong answer.

admin
Site Admin
Posts: 10066
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1180 :

Post by admin »

The explanation is correct. The first o in the given string is a match because it starts with a word boundary i.e. it matches \\bo

I think the words "... any o immediately follows a word boundary ..." ..should be... " any o that immediately follows a word boundary...".
HTH,
Paul.
If you like our products and services, please help us by posting your review here.

RobynBackhouse
Posts: 23
Joined: Sun Apr 14, 2013 10:37 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1180 :

Post by RobynBackhouse »

I'm confused as to why the word boundary itself is not replaced.
If the string is changed to "?O brother", only the "O" is replaced, and the word boundary itself (the ?) is left there, giving the result "?X brother".
Why does the replaceAll not replace the whole regex pattern result?
Thanks
:-)

admin
Site Admin
Posts: 10066
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1180 :

Post by admin »

Because word boundary is considered as zero length. It is not included in the matching value.
-Paul.
If you like our products and services, please help us by posting your review here.

RobynBackhouse
Posts: 23
Joined: Sun Apr 14, 2013 10:37 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1180 :

Post by RobynBackhouse »

Ah ok that makes sense.
Thanks.

The_Nick
Posts: 132
Joined: Thu May 16, 2013 9:23 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1180 :

Post by The_Nick »

Hi,
In your explanation you mention that a word boundary matches also special characthers.. what kind of special characters are you talking about?
Thanks in advance.
The_Nick.

admin
Site Admin
Posts: 10066
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1180 :

Post by admin »

Anything that is not considered a word char i.e. a-zA-Z0-9_. So word boundary will match characters like ;- etc. Please see the JavaDoc for the exact list.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

sir_Anduin@yahoo.de
Posts: 62
Joined: Fri Aug 07, 2015 2:16 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1180 :

Post by sir_Anduin@yahoo.de »

what do you mean by
(Depending on ?m)

admin
Site Admin
Posts: 10066
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1180 :

Post by admin »

If you specify ?m in your expression, it will match line break otherwise not.
See this for details:
http://www.mkyong.com/regular-expressio ... mple-java/
and
http://stackoverflow.com/questions/3651 ... expression
If you like our products and services, please help us by posting your review here.

horst1a
Posts: 37
Joined: Mon Jun 12, 2017 2:16 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1180 :

Post by horst1a »

Where is the word boundary here, before the first o ?

admin
Site Admin
Posts: 10066
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1180 :

Post by admin »

Yes, that is the first word boundary.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 255 guests