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
End of line period
Moderators: AmigoJack, bbadmin, helios, MudGuard
- Bob Hansen
- Posts: 1516
- Joined: Sun Mar 02, 2003 8:15 pm
- Location: Salem, NH
- Contact:
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.
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.
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.
Search for:^(.*)([^_.?!])(_)*$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!
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
Bob
Replace by
if empty lines should get a dot as well, use instead.
if whitespace after ? or ! or . is allowed replace or by
(of course, posix syntax is needed)
Code: Select all
([^?!.])$Code: Select all
\1.Code: Select all
(^|[^?!.])$if whitespace after ? or ! or . is allowed replace
Code: Select all
([^?!. \t])([ \t]*)$Code: Select all
(^|[^?!. \t])([ \t]*)$Code: Select all
\1.\2(of course, posix syntax is needed)
- Bob Hansen
- Posts: 1516
- Joined: Sun Mar 02, 2003 8:15 pm
- Location: Salem, NH
- Contact:
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.
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
Bob