• 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
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

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: 13073
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?
 
Eat that pie! EAT IT! Now read this tiny ad. READ IT!
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic