aspose file tools*
The moose likes Beginning Java and the fly likes Issue Regarding Regular Expression Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Issue Regarding Regular Expression" Watch "Issue Regarding Regular Expression" New topic
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: 230
    
    2

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: 230
    
    2

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: 24
@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: 230
    
    2

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 .


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Issue Regarding Regular Expression