• 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

Metacharacter looks for alphabetics

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok here's the question:

Which are true about java regex



One answer is:

The '.' metacharacter searches for alphabetic characters



The Learn Key Master Exam maintains that this answer is false because the '.' metacharacter searches for everything that is not a newline.

I would maintain that this true for exactly that reason! Alpha numerics are a subset of the group that this metacharacter searches for. It searches for anything that is not a new line.

So if I'm searching for A and B is a subset of A then it's implied that I am searching for B if B is a member of A.. And if any of you study boolean algebra you would know that if B is included in set A then B -> A.


Here is some proof: Ok so if this statement above is false it means that the statement : "The '.' metacharacter does not search for alphabetic characters" is true
Let's test that out.



Is the code we're gong to use. Now, we have to assume that if something is found by a regular expression pattern, then that pattern is indeed looking for it.

Proof:

Let's take the pattern \d*. This example is in one of the self tests in Sierra and Bates' book, actually. If we are given the string 'abdrf1232' , what would the result be? We know that the expression is looking for 0 or more digits. So, it's looking for digits.

Let's modify the code above to do this.



Here is the output:

index 0:
index 1:
index 2:
index 3:
index 4:
index 5: 1232
index 9:
we find that start() is setting the index each time while group() is giving us what we are looking for.. So we know that the ouput of group() is what the expression is looking for.

So then let's run the first code with the '.' metacharacter.

Here is the output:

index 0: O
index 1: C
index 2: J
index 3: P

This means that '.' absolutely searches for alphabetic characters.

I saw this question on one of the practice tests in the Learn Key Master Exam and I canceled my appointment. I'm not going to get certified by people who think that this is good code or even correct in any way.


All of you: You want to prove that you can develop in java.. Get a source forge or github account and write some java code. Not a OCJP certificate.

You'll be a better programmer for it too.

 
No, tomorrow we rule the world! With this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic