This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Pattern Matching

 
harmeet saini
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Follwing is a question from K&B chapter 6 Self Test

And the command line :

java Regex2 "\d*" ab34ef

Answer given is 01234456

When I ran this program I am not getting any output, I am not able to understand why this is happening. Please help

Thanks
 
Ankit Garg
Sheriff
Posts: 9497
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check this faq...
 
harmeet saini
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks ankit for sharing the link, however i have two doubts

1) why my machine is not giving me any output for pattern "\d*" althought playing with it like "\d+" od "\d" is giving me output
2) as per the docs i am not able to understand the index of each character in the string, means does the character "a" is at index 0 or at 1

Thanks in advance
 
Ankit Garg
Sheriff
Posts: 9497
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops I didn't see that you were having problems with getting an output. Are you running the program from command line or some IDE?? Also make sure to include the "" around \d* as * has special meaning for windows command line.
For the index of a, its 0...
 
harmeet saini
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am running the program from command line and have used "" around \d* still its not giving me the output, is it like this expression gives different output for different JVM's , althought i don't find any reason for this

for my 2nd doubt ,so it means the expression "\d*" find a expression of zero length after the string "ab34ef" that is at index 6 ? although the last index is 5(i.e "f").

Thanks in advance
 
Ankit Garg
Sheriff
Posts: 9497
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
harmeet saini wrote:so it means the expression "\d*" find a expression of zero length after the string "ab34ef" that is at index 6 ? although the last index is 5(i.e "f").

Well there will be a zero length match *after* f which is the index 6
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic