• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Pattern Matching

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check this faq...
 
harmeet saini
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic