| Author |
Issue Regarding Regular Expression
|
buntha Choudhary
Ranch Hand
Joined: Jul 03, 2009
Posts: 136
|
|
I am reading the the regular expression tutorial in Sun java.(http://download.oracle.com/javase/tutorial/essential/regex/bounds.html)
Under Boundary Matchers , 1 scenario is like -
Matcher String = ^dog$
Input String = dog
Expected Result : failed
Actual Result : "dog" starting at index 0 and ending at 3
Why I am not getting the No match found as I am appending space infront the dog string and according to the ^dog$ , string should start with d.
|
 |
Raymond Tong
Ranch Hand
Joined: Aug 15, 2010
Posts: 156
|
|
Where did you get the source code of the sample ? or you made one youself ?
I have tried the RegexTestHarness and I got the expected result.
|
 |
buntha Choudhary
Ranch Hand
Joined: Jul 03, 2009
Posts: 136
|
|
Source Code -
|
 |
Raymond Tong
Ranch Hand
Joined: Aug 15, 2010
Posts: 156
|
|
buntha Choudhary wrote:Source Code -
Try to print the content of scan.next() before passing to the matcher method
|
 |
Gaurav Sainii
Greenhorn
Joined: May 18, 2009
Posts: 23
|
|
@buntha: the code you provided is working fine by passing the specified pattern.
Though you can try hardcoding the pattern and then pass the input to test the same.
The code is anyhow still correct and working fine.
|
 |
buntha Choudhary
Ranch Hand
Joined: Jul 03, 2009
Posts: 136
|
|
This issue is coming because scan.text() is trimming the space or it is considering only dog as string even I am providing the space before that.
|
 |
Raymond Tong
Ranch Hand
Joined: Aug 15, 2010
Posts: 156
|
|
buntha Choudhary wrote:This issue is coming because scan.text() is trimming the space or it is considering only dog as string even I am providing the space before that.
Have a look on Scanner in Java API Doc.
You would know why.
|
 |
buntha Choudhary
Ranch Hand
Joined: Jul 03, 2009
Posts: 136
|
|
Thanks to all .
|
 |
 |
|
|
subject: Issue Regarding Regular Expression
|
|
|