Paul Cook
Paul Cook

Reputation: 27

Regex to to add periods after single capitals but only up to "|" in line

I'm working on a 3.75 million line text catalog of Authors names and titles in Editpad Pro. I need to standardize the authors initials to have periods after them.

The catalog has the authors name and book titles separated by a vertical bar "|" character, like this:

A N Author|A Title
A. N. Name|A Blah
Some A Name|Blah A Lot
A Name|Blah I
Name A|I Blah
B O'Name|A Book

Normally in Calibre I use this regex to standardize the initials

\b([A-Z])\.?\s?(?!'|\-|\.)\b
Replace:"\1. "

but here I need it to only work up to the vertical bar "|" character, and not make any changes to the titles. I cannot seem to get anything to work on all the above authors names without it also changing the titles.

Results I'm looking for:

A. N. Author|A Title
A. N. Name|A Blah
Some A. Name|Blah A Lot
A. Name|Blah I
Name A.|I Blah
B. O'Name|A Book 

Thanks.

Upvotes: 1

Views: 34

Answers (1)

Valdi_Bo
Valdi_Bo

Reputation: 30981

Add to your regex a positive lookahead:

(?=.*\|)

It means: Somewhere later in the line there must be a |.

It works as long as there is a single | in the line, but your source text sample meets this condition. Single letters before it are matched, single letters after it aren't.

Upvotes: 1

Related Questions