Why doesn't this work?

General questions about using TextPad

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

Post Reply
pb4072
Posts: 14
Joined: Tue Nov 10, 2009 7:24 pm
Location: Washington, DC area

Why doesn't this work?

Post by pb4072 »

Hi,
I need to keep the first word of every line, but, remove anything thereafter. I need to do this for each line of a 150 line file.

I'm searching for this:

^(.*$)(.*)$

I'm replacing with this:

\1

When I run this, it's removing everything. I'm left with blankness. Interestingly, in version 5 of Textpad, which I had until a few minutes ago, it simply replaced every line with itself. It didn't remove anything. But, now, with version 7, it's removing everything. Whatever. I just want it to keep the first parenthetical expression. Why doesn't it?

Thanks,
Peter
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

$ matches the end of a line (not the end of a word). So your first parenthesised subexpression matches the whole line. The second one matches everything that's left on the line: that is, nothing.

Try
Find what: ^(\S+).* [That's an upper-case S]
Replace with: $1
which keeps everything up to (but not including) the first white space character on each line.

I've used the new-style $1 instead of \1 in the replacement expression to represent what was matched by the first parenthesised subexpression (although it happens that \1 still works).
Post Reply