#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2015
    Posts
    4
    Rep Power
    0

    Find and replace help


    Hi. Brand new to reg exps, I know what I want, can you point me in the right direction please.
    I need a proof reading find and replace. I need to search for this:

    Capital letter followed by any string ending with a double quote (")

    I need to replace with:

    Capital letter followed by any string ending with a comma after the last word then a space followed by the double quote (")

    Here's an example: The cat then said "Hi!" Replace with: The cat then said, "Hi!"

    These issues crop up so often in proofreading and Word 'find and replace' can't quite cut it.
    Hope this is clear
  2. #2
  3. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,553
    Rep Power
    4549
    Are you planning on using VB, VB.net, VBA, VBScript? If you have some piece of code that's giving you problems post the code and a description of the problem.

    Microsoft has good documentation online for all the various string-handling and regex functions in various versions of VB.
    ======
    Doug G
    ======
    I've never been able to appreciate the sublime arrogance of folks who feel they were put on earth just to save other folks from themselves .." - Donald Hamilton
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2015
    Posts
    4
    Rep Power
    0
    Originally Posted by Doug G
    Are you planning on using VB, VB.net, VBA, VBScript? If you have some piece of code that's giving you problems post the code and a description of the problem.

    Microsoft has good documentation online for all the various string-handling and regex functions in various versions of VB.
    Hi Doug, many thanks for taking the time to reply. I guess I will be using VBA, I have some experience with that and want it to work within word docs. No code at the moment, before I start fiddling I would just like to know what I would use to denote a string of any length in the code. So the key part I need for the search is (sorry to repeat)
    (Capital letter) (string) (speech marks)

    Then use that string in the replace tagging a comma on the end of it. Any quick ideas for string of any length? Obviously I am only matching the pattern, not a specific string.

    Thanks again.
  6. #4
  7. Lord of the Dance
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Oct 2003
    Posts
    4,131
    Rep Power
    2011
    The issue with Regex is that it can be quite greedy if you are not careful and look at specific element.

    With your example: The cat then said "Hi!"
    and this pattern: (Capital letter) (string) (speech marks)
    it will also match this part: The cat then said "
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2015
    Posts
    4
    Rep Power
    0
    Hi MrFujin

    That's fine, that's all what I want:

    The cat then said "

    And then replace with

    The cat then said, "

    Of course I want any string between cap letter and "

    Best

    dontavacat
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2015
    Posts
    4
    Rep Power
    0
    Never mind I'll do it myself. I'll put the answer up here when I have it.

IMN logo majestic logo threadwatch logo seochat tools logo