• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

String processing - Is Paul right in his assumption?

 
Author
Posts: 375
22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone -

Its an honor to promote my book at JavaRanch.
To make this promotion interesting, I'll post questions or code for ranchers to answer.

So here's a quick question on String processing.

==================================
Paul says that the output of the following code is 'How much wOOd would a wOOdchuck chuck if a wOOdchuck could chuck wOOd?'
Do you agree?



With much respect,
Mala

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, because \W is a regular expression for non-word character, so in this case all non-word characters will be replaced with "OO" (white-spaces and the question mark)
 
Mala Gupta
Author
Posts: 375
22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mitko -

Perfect answer! So let's modify it.

Can you (or anyone else) modify the regex used in this code so it modifies the string, as shown in the image.



With much respect,
Mala


 
Mitko Stankov
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In this case you can use a boundary matcher "\b" (a word boundary) to determine the occurrence of the 'w' character as a first letter of the word and replace it with 'W'.

 
reply
    Bookmark Topic Watch Topic
  • New Topic