• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Matt Taylor
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • 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
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • 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
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
specifically, what do the square brackets in a regex mean?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!