Win a copy of Head First Android this week in the Android forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Regex; Unable to follow difference in output

 
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Chapter 6, Sierra/Bates, modified code:



Pattern proj[\\d]([^,])*
Source proj3.txt,proj1sched.pdf,proj1,proj2,proj1.java

I understand the output, which is

0
10
25
31
37


However, I made a slight change to the source (comma between pdf and proj1 is now period):

Source proj3.txt,proj1sched.pdf.proj1,proj2,proj1.java

And now I cannot understand why the output has changed to:

0
10
31
37


The pattern only mentions proj, followed by digit, followed by zero or one comma; nothing about period.

Below is the new code in its entirety:

 
Creator of Enthuware JWS+ V6
Posts: 3398
312
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sandra,

The pattern only mentions proj, followed by digit, followed by zero or one comma; nothing about period.



The key thing here is the ([^,])* meaning not a comma (0 to many times) so,

proj1sched.pdf.proj1 will be seen as one match

Regards,
Frits
 
Sandra Bachan
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@ Fritz: Thanks, I now understand your explanation.

Seems that Regex is one of those things you really need to understand and follow!
 
reply
    Bookmark Topic Watch Topic
  • New Topic