Any way to make MS Word wildcard search greedier?
论题张贴者: Samuel Murray
Samuel Murray
Samuel Murray  Identity Verified
荷兰
Local time: 04:07
正式会员 (自2006)
English英语译成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
西班牙
Local time: 04:07
English英语译成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
Riccardo Schiaffino  Identity Verified
美国
Local time: 20:07
正式会员 (自2003)
English英语译成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
Samuel Murray  Identity Verified
荷兰
Local time: 04:07
正式会员 (自2006)
English英语译成Afrikaans南非语
+ ...
主题发起人
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
荷兰
Local time: 04:07
正式会员 (自2006)
English英语译成Afrikaans南非语
+ ...
主题发起人
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?






CafeTran Espresso
You've never met a CAT tool this clever!

Translate faster & easier, using a sophisticated CAT tool built by a translator / developer. Accept jobs from clients who use Trados, MemoQ, Wordfast & major CAT tools. Download and start using CafeTran Espresso -- for free

Buy now! »
Trados Studio 2022 Freelance
The leading translation software used by over 270,000 translators.

Designed with your feedback in mind, Trados Studio 2022 delivers an unrivalled, powerful desktop and cloud solution, empowering you to work in the most efficient and cost-effective way.

More info »