• 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

How can I remove whole word when a pattern matches in a string?

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"This is an sample or example of String"

I want to remove all words containing "ample" whether they are in the beginning, middle or end of a sentence.

I want to result in:

"This is an or of String"


My regex is [.ample] but it is not working
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Matt Taylor wrote:I want to remove all words containing "ample" whether they are in the beginning, middle or end of a sentence.
My regex is [.ample] but it is not working


Unsurprising.

Do you know what the regex "[.ample]" actually does (or matches)?

My suggestion: Read a good tutorial. I've generally found this site pretty good.

Alternatively, there is a summary of Java regex expressions in the Pattern class docs, but it doesn't provide much context.

Regexes are NOT simple, so you can't expect to simply write one out and expect it to work.

HIH

Winston
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
specifically, what do the square brackets in a regex mean?
 
reply
    Bookmark Topic Watch Topic
  • New Topic