Results 1 to 5 of 5
  1. #1
    Star Lounger
    Join Date
    Jan 2016
    Posts
    77
    Thanks
    18
    Thanked 1 Time in 1 Post

    Wild Card Search - Delete Text - Only if it's on a blank line

    Hi folks,

    hope all are well


    I am trying to work out how to do a wild card search with no luck

    I only want to delete the word Apple if its on a line by it self. So on a new line by itself .


    ==================
    Apple In porta quis eros id viverra. Aliquam tincidunt in leo a aliquam.
    Phasellus posuere ex quis dui condimentum iaculis. Vivamus magna justo, ultricies non vulputate at, consequat nec velit.
    Apple
    Apple Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut eu risus ut risus malesuada pretium.
    Apple
    ================

    (Apple)(*) ?

    Any tips welcome

    thank you

    pb

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    PB,

    This is a some what thorny problem as you don't specify what constitutes a line of it's own. One definition would be a paragraph mark before and after. However, what about a New Line before and after or Newline before and Paragraph Mark after and visa versa.

    Luckily we have regular expressions that can handle all those situations.

    So in the Find and Replace dialog box:

    Find What: ([^11^13])([Aa]pple)([^11^13])

    Replace with: \1\3



    Use wildcards: CHECKED

    Before:
    AppleBefore.PNG

    After:
    AppleAfter..PNG

    How this works:

    In the Find what:
    () denotes groups, to be used later in the Replace with.
    [] denotes any match so [^11^13] means either a NewLine or a Paragraph Mark. You'll notice the [Aa] to get apple or Apple.

    In the Replace with:
    \n replace with the contents of the group n from the Find what. In this case we're keeping the preceeding New Lines and Paragraph marks {\1} and the trailing New Lines and Paragraph marks {\3}, which will leave a blank line. If you want to get rid of the blank line just use either the \1 or \3.

    HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  3. The Following User Says Thank You to RetiredGeek For This Useful Post:

    pb89 (2016-02-13)

  4. #3
    Star Lounger
    Join Date
    Jan 2016
    Posts
    77
    Thanks
    18
    Thanked 1 Time in 1 Post

    Smile

    RG,

    the forces of good computing are with you.

    Jedi trick -


    I have been at it for hours

    You know it seems like such a simple thing - just delete it if its by itself - yet it is complex -

    I had many versions of below similar - just couldn't work it out - also the replace had no clue to do it that way.

    ([^11])([A]apple)


    May I say it is very nice of you to donate your time and to annotate it as per the post.

    Thank you so much - I have got great ideas to extend it - incorporate it into a macro

    Have a great Saturday cheers:

    and thanks again - RG - Super Man!

    pb:

    Solved

  5. #4
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    PB,

    You're most welcome!

    BTW: You can mark the thread solved by using the Thread Tools link at the top of the page.
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  6. #5
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts
    pb89: You might find the following link instructive - http://word.mvps.org/FAQs/General/UsingWildcards.htm
    Cheers,

    Paul Edstein
    [MS MVP - Word]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •