| 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
|
|
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.
|
 |
 |
|
|
subject: regex doubt in oracle tutorials ?
|
|
|