• 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

A regex question

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe this is a little naive...

On p. 483 of K & B (Java 1.5), the test run in the command line is:

% java Regex "\d\w" "ab4 56_7ab"

Why use "\d\w" instead of "\\d\\w"? args[0] is a String,
should there be an additiona backslash to escape \ in \d?

Thanks.
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Whether you need to escape the backslash or not is dependant on the shell you exec java from. For the exam it is not necessary to know what shell the questions will be running in or whether or not back slashes need to be escaped.

Kristian
 
reply
    Bookmark Topic Watch Topic
  • New Topic