regular expression with replace condition RRS feed

  • Question

  • I want to do a search and replace within a word file.

    The search will be for a character and replace depend on the next character. If the next character is "a", "b", "c" or "d" I need to replace the searched character with "u", if the next character is "f" I need to know what is the next character1, and if the next character is "g", i will replce the searched character "u", if non of this then continue to the next.

    i.e, search for Y in  "Ykl Yc Yfg Yfh" text, the replace should do:"Ykl uc ufg Yfh"
    Any help will be appreciated, Thanks 
    Tuesday, January 15, 2013 2:39 AM


  • I take it this is related to your other question

    Does the other question supercede this one (this one is now meaningless)?

    Word has no option for using Regular Expressions, only its Find.Execute facility. That does have "Wildcard" capability, but I don't think that will do what you describe.

    The only way you can use regular expressions with content in a Word document would be to work with Office Open XML, not with the Word APIs. Office Open XML lets you open the document outside of Word; using standard Packaging and XML namespaces you can work with the document content (including using Regular Expressions).

    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, January 15, 2013 6:56 AM