Any way to make MS Word wildcard search greedier?
Thread poster: Samuel Murray

Samuel Murray  Identity Verified
Netherlands
Local time: 22:21
Member (2006)
English to Afrikaans
+ ...
Mar 4, 2013

G'day everyone

I have a macro that changes the style of certain pieces of text. The macro works fine except that it matches the smallest possible match instead of the largest possible match. I understand that this is a feature of MS Word's regex -- it is non-greedy. However, is there some way to make it greedy?

For example, if my text is "one one one one two three one two three" and I want everything from the first "one" to the very last "one" to be selected, how can I do that?

I don't need to worry about matching too much, because I have already marked some text as highlighted and I run my regex only on highlighted text, but I do want the match to be as greedy as possible within that text. I don't know in advance how many matches for a pattern there will be in any given search.

Thanks
Samuel

Oh, I'm using Word 2003, by the way.


 

Oscar Martin
Spain
Local time: 22:21
English to Spanish
+ ...
Use of curly braces Mar 4, 2013

Try using curly braces as in the example:

(one ){1,}

The comma (or separator) may vary according to regional OS settings. This will find all instances of the term between brackets (from 1 to n).

Oscar


 

Riccardo Schiaffino  Identity Verified
United States
Local time: 14:21
Member (2003)
English to Italian
+ ...
That's not what Samuel was trying to do Mar 4, 2013

Oscar Martin wrote:

Try using curly braces as in the example:

(one ){1,}

The comma (or separator) may vary according to regional OS settings. This will find all instances of the term between brackets (from 1 to n).

Oscar


I believe that what Samuel was trying to do is not "finding all instances of the term", but finding a string ending with the furthest instance of the term.

i.e, he wants a greedy regex search that, when searching

"one one one one two three one two three"

finds "one one one one two three one",

and not "one" repeatedly.

This is, AFAIK not possible using the MS Word subset of regex, but it is indeed possible in other regex implementations; for example, in Notepad++, this would be very easy to accomplish by using the regex search .*one



[Edited at 2013-03-05 04:20 GMT]


 

Samuel Murray  Identity Verified
Netherlands
Local time: 22:21
Member (2006)
English to Afrikaans
+ ...
TOPIC STARTER
Indeed... Mar 5, 2013

Riccardo Schiaffino wrote:
I believe that what Samuel was trying to do is not "finding all instances of the term", but finding a string ending with the furthest instance of the term.


Indeed. What I want to do is to mark tags as external if they hug the edges of the segment, but not if they're elsewhere in the segment.

Suppose I have this:

[segment 1]{0}{1}{2}Some text here{3} and here.

...then I want a way to tell Word to select this:

[segment 1]{0}{1}{2}

...so that I can mark it all as external text. At this moment, I can mark [segment 1]{0} as external text but I have to mark {1}{2} as internal text because I have no way of selecting it while marking stuff as external text. I can't simply mark all tags as external -- I only want to mark tags as external if they hug the edges of the segment.

Hmm, bummer.


 

xxxtrhanslator
Are you referring to {UT} tags at the segments start in Wf Pro Mar 7, 2013

Samuel Murray wrote:

[segment 1]{0}{1}{2}Some text here{3} and here.

...then I want a way to tell Word to select this:

[segment 1]{0}{1}{2}



Are you by any chance referring to {UT} tags at the segments start in Wf Pro?


 

Samuel Murray  Identity Verified
Netherlands
Local time: 22:21
Member (2006)
English to Afrikaans
+ ...
TOPIC STARTER
No... the format I use this macro on is TTX Mar 7, 2013

trhanslator wrote:
Samuel Murray wrote:
[segment 1]{0}{1}{2}Some text here{3} and here.
...then I want a way to tell Word to select this:
[segment 1]{0}{1}{2}

Are you by any chance referring to {UT} tags at the segments start in Wf Pro?


No, I used curly brackets here only for illustration. The format I use the macro on is TTX.


 

xxxtrhanslator
What you want to do is possible Mar 7, 2013

What you want to achieve is possible but it needs some real VBA coding. You could direct a request to the Word VBA forums that exist.

 


To report site rules violations or get help, contact a site moderator:


You can also contact site staff by submitting a support request »

Any way to make MS Word wildcard search greedier?

Advanced search






PerfectIt consistency checker
Faster Checking, Greater Accuracy

PerfectIt helps deliver error-free documents. It improves consistency, ensures quality and helps to enforce style guides. It’s a powerful tool for pro users, and comes with the assurance of a 30-day money back guarantee.

More info »
Déjà Vu X3
Try it, Love it

Find out why Déjà Vu is today the most flexible, customizable and user-friendly tool on the market. See the brand new features in action: *Completely redesigned user interface *Live Preview *Inline spell checking *Inline

More info »



Forums
  • All of ProZ.com
  • Term search
  • Jobs
  • Forums
  • Multiple search