End of line period

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, MudGuard

Post Reply
George Musick
Posts: 5
Joined: Sat Jun 21, 2008 2:19 pm

End of line period

Post by George Musick »

How do I add a period "." to the end of each line if there isn't already a ".", "?" or "!" there? To be safe, I think I need to remove trailing spaces first.

Thanks,
George
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

Quick and dirty, not pretty at all.....

1. Add a period to the end of every line.
2. Replace ".." with "."
3. Replace "?." with "?"
4. Replace "!." with "!"

========================
Better solution will be RegEx, should look something like this UNTESTED sample. Should add period if no punctuation, and strip trailing spaces also:

Use this as a test file, insert trailing spaces on two lines as noted.
This line has a period at the end.
This line has NO punctuation
This line has one trailing space
This line has a question mark?
This line has two trailing spaces
This line has an exclamation point!
Search for:^(.*)([^_.?!])(_)*$
Replace with:\1\2.
Note: The _ character is for space character

No access to TestPad right now, so cannot do RegEx tests. The RegEx strings above are best guess, but probably need to be tweaked.
Last edited by Bob Hansen on Sat Jul 25, 2009 5:58 am, edited 2 times in total.
Hope this was helpful.............good luck,
Bob
User avatar
MudGuard
Posts: 1295
Joined: Sun Mar 02, 2003 10:15 pm
Location: Munich, Germany
Contact:

Post by MudGuard »

Replace

Code: Select all

([^?!.])$
by

Code: Select all

\1.
if empty lines should get a dot as well, use

Code: Select all

(^|[^?!.])$
instead.

if whitespace after ? or ! or . is allowed replace

Code: Select all

([^?!. \t])([ \t]*)$
or

Code: Select all

(^|[^?!. \t])([ \t]*)$
by

Code: Select all

\1.\2

(of course, posix syntax is needed)
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

Aaah! I see that MudGuard has also submitted his solutions.

I just came back to put up an updated RegEx, turns out to be very similar to his, but he was quicker.

Search for: ([^.?!])(_)*$
Replace with: \1.
Note: The imbedded _ is for the space character.

Again, this will insert the period if no existing punctuation, and will also remove trailing spaces before inserting a final period. If there are trailing spaces after an existing punctuation mark, then an additional period will result.
Hope this was helpful.............good luck,
Bob
Post Reply