Multiple search/replace from start of each line

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
lyle.walker
Posts: 2
Joined: Sun Feb 22, 2015 1:18 am

Multiple search/replace from start of each line

Post by lyle.walker »

I need to add full stops to initials in a series of records, but only for the records where the first character is an alpha. Other records not beginning with a name may also contain initials but these must not be touched.

so like example:
Smith, Robin John G H C, bla, bla...
Thompson, Ian P, bla, bla..


I can limit initial matches with the following regex:

Code: Select all

^([[:alpha:]].*?\<[[:alpha:]]\>)([, ])
and then replace with and added full-stop as follows:

Code: Select all

$1.$2
This finds the "G" above, but then due to the cursor positioning after match, it does not find the H and C in that same record.

Is there some way to achieve this, without repeating the replace all on the file multiple times?

I am using Textpad 8.2

thanks, Lyle
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

If the maximum number of initials is small you might try matching up to that number of them and using conditional expressions in the replacement, but I seriously wouldn't recommend it.

Otherwise, there is no way I know of to do what you want in a single application of a repeated replacement because, as you say, once each replacement is made the cursor is moved to the end of what was matched, and the preceding context is lost.
lyle.walker
Posts: 2
Joined: Sun Feb 22, 2015 1:18 am

Post by lyle.walker »

Thank you Ben.

The data are too varied for the option of conditional expressions, as far as I could construct. Initials may not be all together in one spot, and include compound abbreviations.

I can repeat my replace-all say 3-4 times inside a macro, it may take a fraction longer to run.

But conditional expressions look quite interesting, and I must practice them for other situations.

Lyle
User avatar
AmigoJack
Posts: 596
Joined: Sun Oct 30, 2016 4:28 pm
Location: グリーン ヒル ゾーン
Contact:

Post by AmigoJack »

I'm surprised this works for you in the first place, neither distinguishing between upper and lowercase, nor disallowing non-letters. And not thinking about edge cases. It should also match the bold parts of these examples:
  • Match a word
  • Charles I, prince Kent III
  • Mary and I had fun
  • Mary & I walked
  • Could I, please?
  • CO2+N goes
  • ISTC: A02-2009-000004BE-A, ISBN: 978-3-16-148410-0
In other words: are you sure you have no false positives?
Post Reply