This week's book giveaway is in the Agile forum.
We're giving away four copies of Head First Agile and have Andrew Stellman & Jennifer Greene on-line!
See this thread for details.
Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Pattern Matching  RSS feed

 
harmeet saini
Ranch Hand
Posts: 33
  • 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: 9610
37
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check this faq...
 
harmeet saini
Ranch Hand
Posts: 33
  • 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: 9610
37
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 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
  • 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: 9610
37
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!