Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Issue Regarding Regular Expression

 
buntha Choudhary
Ranch Hand
Posts: 136
Android Eclipse IDE Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 241
2
IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 136
Android Eclipse IDE Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Source Code -


 
Raymond Tong
Ranch Hand
Posts: 241
2
IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
buntha Choudhary wrote:Source Code -


Try to print the content of scan.next() before passing to the matcher method
 
Gaurav Sainii
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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
Posts: 136
Android Eclipse IDE Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 241
2
IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 136
Android Eclipse IDE Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to all .


 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic