Win a copy of TDD for a Shopping Website LiveProject this week in the Testing 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:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Locating data via pattern matching

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Here is the test run:
% java Regex "\d\w" "ab4 56_7ab"

The output is:

Pattern is \d\w
4 56
7 7a

Hi everyone

I have a problem with above code from k&b scjp 6 studyguide chapter 6 pg 499, i compile and run this code and i was expecting the above output, but i got an exception.

I would like to know where to put test run :

% java Regex "\d\w" "ab4 56_7ab" to get the above output .

I understand that d is looking for digit and w is looking for word character, am not clear about the output. Please can you explain to me, i will appriciate your assistance.


 
author & internet detective
Posts: 41073
848
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What exception did you get when running?
 
Harold Ndou
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got this:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at Regex.main<Regex.java:4>
 
Jeanne Boyarsky
author & internet detective
Posts: 41073
848
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm. That means Java sin't recognizing your command line arguments. Are you running this at the command line or through an IDE?
 
Harold Ndou
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was running it on the textpad, how to do it on the command line
 
Jeanne Boyarsky
author & internet detective
Posts: 41073
848
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) Open a command line
2) cd to the directory containing the program
3) type: java Regex "\d\w" "ab4 56_7ab"

Alternatively, the last line of this page says how to use Textpad to pass command line arguments.
 
My pie came with a little toothpic holding up this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic