0

I need to find all the words which contain a specific sequence of characters and delete them.

For example: I want to delete all the words which contain 'all'. This will delete 'hallway', 'wallet', ...

I believe that the SQL equivalent would be: LIKE '%all%'. What is its RegEx equivalent please?

4
  • Do you want to delete "allow" and "hallway", too? Have you looked at regular-expressions.info ?
    – johnsyweb
    Commented May 11, 2012 at 17:08
  • No, all is in the middle but the previous characters in the word can be special characters Commented May 11, 2012 at 17:11
  • You said "all the words which contain 'all', but your examples end with 'all'. This is not the same. What do you mean by "special characters"?
    – johnsyweb
    Commented May 11, 2012 at 17:15
  • 1
    @user1288160, please edit the question to reflect the addition rule you mention above (and any others you might be overlooking).
    – trebormf
    Commented May 11, 2012 at 17:15

4 Answers 4

3

If you want words with "all" anywhere within them, you would use:

\w*all\w*

If you want words with "all" only at the middle or end, you would use:

\w+all\w*

If you want words with "all" only at the end, you would use:

\w+all(?=\W)
2

This is pretty trivial and I do suggest you check out some of the regular expression cheatsheets you can find on the web.

.*all.*
2
  • 1
    This will affect all lines containing 'all'.
    – johnsyweb
    Commented May 11, 2012 at 17:15
  • Agreed. That would be closest to a SQL LIKE.
    – Tremmors
    Commented May 11, 2012 at 17:44
1
"Find what": \w*all\w*
"Replace with": <nothing>
"Search mode": Regular expression
4
  • 1
    This will affect all lines containing 'all'.
    – johnsyweb
    Commented May 11, 2012 at 17:15
  • @Johnsyweb You're right, such a simple one will not do in this case. But the TS has accepted the same answer, so maybe it does what he needs... Commented May 11, 2012 at 17:25
  • Or more likely, the OP didn't know the answer to begin with and just accepted, without knowing whether it was correct. Commented May 11, 2012 at 17:26
  • @AndrewBarber Yes, this is more likely. Commented May 11, 2012 at 17:32
0

Try to add spaces Around the specific word you want to
terminate, for your example! space(specific word)space, this will avoid to delete similar word as hallway, wall, tall, ball or ally, etc... Try below regex

Find what: .*\sall\s.*
Replace with: leave it empty

Not the answer you're looking for? Browse other questions tagged or ask your own question.