replacing first character of line only

General questions about using TextPad

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

Post Reply
richardk
Posts: 4
Joined: Wed Jan 27, 2016 12:41 am

replacing first character of line only

Post by richardk »

When I do regex:

find: ^a
replace: (no character, blank)

on file with:

aaaaa

It replaces all the a's, not just the first one.

I want to replace only the first a, it used to work on textpad.
Not sure why it is not working now.
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

TextPad removes the a at the beginning of the line. The next a is now at the beginning of the line, so TextPad removes that. And so on. Perhaps TextPad shouldn't behave like this.

There are several ways to solve this. Here are two:
Find what: ^a(.*)
Replace with: $1
Find what: ^a(?=.|$)
Replace with: [nothing]
richardk
Posts: 4
Joined: Wed Jan 27, 2016 12:41 am

Post by richardk »

Thanks, that works great!
Post Reply