Finding SHORTEST Text

Everything related to our flagship word processor.
Post Reply
waltzmn
Posts: 50
Joined: 2013-05-05 12:52:00

Finding SHORTEST Text

Post by waltzmn »

I feel as if I ought to know this, but I just can't make it work.

I have a list of bibliographic references that I need to clean up. Every entry has an abbreviation at the beginning, followed by a colon and space, then the actual entry. Here are three example lines:

Chambers: E. K. Chambers, _English Literature at the Close of the Middle Ages_, Oxford, 1945, 1947
Chaucer/Benson: Larry D. Benson, general editor, _The Riverside Chaucer_, third edition, Houghton Mifflin, 1987
Dobson/Taylor: R. B. Dobson and J. Taylor, _Rymes of Robyn Hood: An Introduction to the English Outlaw_, University of Pittsburg Press, 1976


What I want to eliminate is everything up to the first colon (the parts shown in bold), leaving the rest. So the above should become

E. K. Chambers, _English Literature at the Close of the Middle Ages_, Oxford, 1945, 1947
Larry D. Benson, general editor, _The Riverside Chaucer_, third edition, Houghton Mifflin, 1987
R. B. Dobson and J. Taylor, _Rymes of Robyn Hood: An Introduction to the English Outlaw_, University of Pittsburg Press, 1976


So what tried to do is change
\n[^\n\f]+\: +
that is, (return)(any text)(colon)(space)(1+)
to just plain
\n
that is, (return).

This of course works for the first two lines, but the third line comes back as

An Introduction to the English Outlaw_, University of Pittsburg Press, 1976

It took all text to the last colon in the line, not the first colon.

How do I get the shortest match, not the longest?
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Finding SHORTEST Text

Post by phspaelti »

"+" gives a 'greedy' repetition
"+?" gives the shortest.

By the way in your expression you can just use a position match rather than 'replacing' the return:

^[^\n\f]+?\: +


PS: If you use the Find box, the menus have these repeaters listed :wink:
philip
waltzmn
Posts: 50
Joined: 2013-05-05 12:52:00

Re: Finding SHORTEST Text

Post by waltzmn »

phspaelti wrote:
"+" gives a 'greedy' repetition
"+?" gives the shortest.
Thank you!
PS: If you use the Find box, the menus have these repeaters listed :wink:
Actually, I did use the Find box; I can't remember that "[^\n\f]" part. :) But I didn't know what I should be looking for. :wink:

Again, thank you.
Post Reply