Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word regular expressions 1

Status
Not open for further replies.

CraigMan

Programmer
Apr 27, 2004
33
US
I'm using Word regular expressions in Selection.Find (wildcards ON) to parse sections of a document into excel cells. I have experience with regular expressions and it seems Word has limited functionality in that regard.

My document is laid out like an outline and I'm trying to develop a robust expression to consistently hit each section on a Find. Here's an example:

7.1-1 The rain in spain...
7.1-2 Id est quo vadis...

7.2.1-1 This little piggy...
7.2.1-2 Wee, wee, wee...

7.2.2-1 Huffed and puffed...
etc.

For Selection.Find.Text I tried: ?.?.?-?* [A-Z]
This expression did not pick up 7.1-1 and 7.1-2

I also tried: ?(.?){1,}-?* [A-Z]
This expression picks up 7.1-1 and 7.1-2 but
only pickes up 2.1-1, 2.1-2, and 2.2-1 of the others.

Any ideas?

Craig Meyers, BSNucE, PE
 
Hi Craig,

This is impossible. What passes for a regular expression in Word's F&R would not pass for one anywhere else.

Unfortunately, [blue](.?){1,}[/blue], which you have tried to use does not do what you want or might reasonably expect. When the pattern you are trying to find is an expression, it will find, for example, [green].1.1[/green], or [green].2.2.2[/green] but not [red].1.2[/red] - in other words it finds only repeat occurrences of the found string, not the pattern.

Just to keep you on your toes, when the pattern you are trying to find is a single character rather than an expression, it will find multiple occurrences of the pattern. So [blue][0-9]{1,}[/blue] will find [green]123[/green] but [blue]([0-9]){1,}[/blue] will not find it, finding, instead, [green]1[/green], then [green]2[/green], then [green]3[/green].

There is also no way to find zero or more occurrences of anything and, as far as I know, no way to find what you want in a single operation. Sorry!

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

Professional Office Developers Association
 
Zero or more occurences would definitely help.

It's pretty sad when text editors like Nedit and TextPad have richer search and replace features than Word.

Craig Meyers, BSNucE, PE
 
Actually that's pretty useful but unfortunately it's vbscript. Using Word's built-in Find and Replace has a small subset of the functionality of standard RE wildcards.

Thanks!

Craig Meyers, BSNucE, PE
 
You may instantiate a "VBScript.RegExp" object in VBA.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Very cool. I didn't think of that!

Craig Meyers, BSNucE, PE
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top