Sign in to follow this  
Followers 0
raifwrite

_worddocfindreplace and wildcards

3 posts in this topic

I am trying to do a simple find replace in a Word doc based on a partial string and wildcard but I don't know what syntax to use for the wildcard function. I tried using the SringRegExp syntax also with no success. Could someone please help. I am looking for a text string that begins with the string "xyz" but has any number of letters/numbers after it in the same word.

$oWordApp = _WordCreate ("C:\Documents and Settings\user\Desktop\test.doc")
$oDoc = _WordDocGetCollection($oWordApp, 0)
_WordDocFindReplace ( $oDoc, "xyz*", "replace", 2, 0, 0, 0, 1 )

Share this post


Link to post
Share on other sites



I am trying to do a simple find replace in a Word doc based on a partial string and wildcard but I don't know what syntax to use for the wildcard function. I tried using the SringRegExp syntax also with no success. Could someone please help. I am looking for a text string that begins with the string "xyz" but has any number of letters/numbers after it in the same word.

$oWordApp = _WordCreate ("C:\Documents and Settings\user\Desktop\test.doc")
$oDoc = _WordDocGetCollection($oWordApp, 0)
_WordDocFindReplace ( $oDoc, "xyz*", "replace", 2, 0, 0, 0, 1 )
Word HELP says that when you use wildcards, you search is always case sensitive so you need to use special codes to tell Word how to search.

In this case sqaure brackets if you want to find either "X" or "x". Also, there are special markers to indicate the beginning and ending of words.

If you open Word and call up your "find" dialog, check "use wildcards" and look for the "Special" button near the bottom of the dialog box you'll get all these special codes.

In this case, we're interested in "<" for beginning of word, and ">" for end of word.

So, replace your _WordDocFindReplace line with

_WordDocFindReplace( $oDoc, "<[Xx][Yy][Zz]*>", "replace", 2, 0, 0,0,1)

The only thing this doesn't seem to catch is if you have a word with a hyphen in it.

Hope that helps

Share this post


Link to post
Share on other sites

Word HELP says that when you use wildcards, you search is always case sensitive so you need to use special codes to tell Word how to search.

In this case sqaure brackets if you want to find either "X" or "x". Also, there are special markers to indicate the beginning and ending of words.

If you open Word and call up your "find" dialog, check "use wildcards" and look for the "Special" button near the bottom of the dialog box you'll get all these special codes.

In this case, we're interested in "<" for beginning of word, and ">" for end of word.

So, replace your _WordDocFindReplace line with

_WordDocFindReplace( $oDoc, "<[Xx][Yy][Zz]*>", "replace", 2, 0, 0,0,1)

The only thing this doesn't seem to catch is if you have a word with a hyphen in it.

Hope that helps

Thanks, that got me on the right track. I did not originally make the connection that you had to utilize MS Word's Find syntax to do the text search. Duh!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0