This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes regex doubt in oracle tutorials ? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "regex doubt in oracle tutorials ?" Watch "regex doubt in oracle tutorials ?" New topic
Author

regex doubt in oracle tutorials ?

gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 895

please refer oracle tutorials given at http://docs.oracle.com/javase/tutorial/essential/regex/test_harness.html. when i ran the program and entered the given regex and input string i get the given below result :
Enter your regex: a??
Enter input string to search: aba
I found the text "" starting at index 0 and ending at index 0.
I found the text "" starting at index 1 and ending at index 1.
I found the text "" starting at index 2 and ending at index 2.
I found the text "" starting at index 3 and ending at index 3.

please explain how i'm getting zero-length matches ? i know i'm using reluctant quantifier.


OCPJP 6(100 %) OCEWCD 6(91 %)
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4203
    
    3

gurpeet singh wrote:please explain how i'm getting zero-length matches ? i know i'm using reluctant quantifier.

You're also matching on 'a' once or not at all.


luck, db
There are no new questions, but there may be new answers.
gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 895

Darryl Burke wrote:
gurpeet singh wrote:please explain how i'm getting zero-length matches ? i know i'm using reluctant quantifier.

You're also matching on 'a' once or not at all.



but as you can see from the output, all i'm getting is zero length matches. why it is not matching a. i'm not able to understand.
Helen Ma
Ranch Hand

Joined: Nov 01, 2011
Posts: 451
Have you tried to print the match using start and end ?
gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 895

Helen Ma wrote:Have you tried to print the match using start and end ?



yes helen. the link i gave contains the source code java file for the code given on the oracle tutorials. they have used start and end methods to print the location of the match.
Helen Ma
Ranch Hand

Joined: Nov 01, 2011
Posts: 451
So, I guess the match is



Please verify this.
gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 895

Helen Ma wrote:So, I guess the match is



Please verify this.



but when i run the program named as TestHarness given on oracle site , it does not produce the above output. as mentioned in my original post it produces following output. you can verifiy by running it.

Enter your regex: a??
Enter input string to search: aba
I found the text "" starting at index 0 and ending at index 0.
I found the text "" starting at index 1 and ending at index 1.
I found the text "" starting at index 2 and ending at index 2.
I found the text "" starting at index 3 and ending at index 3
Helen Ma
Ranch Hand

Joined: Nov 01, 2011
Posts: 451
I refer to this web site:
http://www.regular-expressions.info/reference.html

I guess a?? is evaluated as "a" as optional. So, regex a?? means evaluate a substring without or with a. So, "a", "b" , "a" is evaluated in this way:
1. "a" is without "a" --pass evaluation
2. "b" has no "a". --pass evaluation

I guess it has something to do with the compiler design.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: regex doubt in oracle tutorials ?
 
Similar Threads
Regex expressions
Help me unravel the concept of greedy quantifiers.
regular expression greedy quantifier problem
Doubt about Regex and Quantifiers
Brackets [ ] in regular expression