This week's book giveaway is in the Artificial Intelligence forum.
We're giving away four copies of Pragmatic AI and have Noah Gift on-line!
See this thread for details.
Win a copy of Pragmatic AI this week in the Artificial Intelligence 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Different result using Regex example in SCJP6 book  RSS feed

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hey guys,

I did a search and could not find any information on this and it's sort of bugging me. I'm having trouble moving on because I feel like I am missing something.

It concerns the Regex extraction of file names beginning with "proj1" from the text string.

The string looks like this: ..."proj3.txt,proj1sched.pdf,proj1,proj2,proj1.java"... in the book.

The Regex expression in the book is; proj1([^,])*

The results are supposed to be:

10 proj1sched.pdf
25 proj1
37 proj1.java


For some reason when I try this all I get are the numbers without the actual file names. My results look like this: 10 25 37 without the file names.

Could somebody suggest what may be wrong here? I've read through a couple of times and I must be missing something. Could the book be incorrect here?

Thank you for any attention you can give this.

Mark
 
M Davis
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Here's the short mini-program that I am using to test this...

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Probably, you missed it: start() only gives you the starting position of a match. To actually have the matching string, you'd need to use group() method of Matcher class
 
M Davis
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I did miss that. Thank you so much for your response. I appreciate it.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!