Any way to make MS Word wildcard search greedier?
Initiator des Themas: Samuel Murray
Samuel Murray
Samuel Murray  Identity Verified
Niederlande
Local time: 12:02
Mitglied (2006)
Englisch > 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
... See more
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.
Collapse


 
Oscar Martin
Oscar Martin
Spanien
Local time: 12:02
Englisch > Spanisch
+ ...
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
Riccardo Schiaffino  Identity Verified
Vereinigte Staaten
Local time: 04:02
Mitglied (2003)
Englisch > Italienisch
+ ...
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
Samuel Murray  Identity Verified
Niederlande
Local time: 12:02
Mitglied (2006)
Englisch > Afrikaans
+ ...
THEMENSTARTER
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.


 
trhanslator (X)
trhanslator (X)
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
Samuel Murray  Identity Verified
Niederlande
Local time: 12:02
Mitglied (2006)
Englisch > Afrikaans
+ ...
THEMENSTARTER
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.


 
trhanslator (X)
trhanslator (X)
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?






Anycount & Translation Office 3000
Translation Office 3000

Translation Office 3000 is an advanced accounting tool for freelance translators and small agencies. TO3000 easily and seamlessly integrates with the business life of professional freelance translators.

More info »
Trados Business Manager Lite
Create customer quotes and invoices from within Trados Studio

Trados Business Manager Lite helps to simplify and speed up some of the daily tasks, such as invoicing and reporting, associated with running your freelance translation business.

More info »