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
Why doesn't this work?
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
-
- Posts: 2461
- Joined: Sun Mar 02, 2003 9:22 pm
$ 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
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).
Try
which keeps everything up to (but not including) the first white space character on each line.Find what: ^(\S+).* [That's an upper-case S]
Replace with: $1
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).