What are you about to do? Delete lines with only one word.
What is a word? Probably a consecutive string of non-space characters, although you may not want to include _any_ character:
1) A word only contains letters a to z and A to Z
2) A word contains other characters like -, _, / etc.
3) A word does only not contain white space characters
You can use either (Ctrl+F/H for regular or Ctrl+R for advanced) find and replace dialog, to test the regular expression (check that option!) you are about to use.
1) A word only contains letters a to z and A to Z
The regular expression for such a word is [a-zA-Z]+
[...] _____ is a container for any character that will match
a-z _______ means: any character a, z or in-between
+ _________ means: at least one match, but any other consecutive match will also be included
2) A word contains other characters like -, _, / etc.
You can add any other matching character between the square brackets.
The regular expression for such a word could be [-_a-zA-Z]+
I guess the - will be treated just as the - character if it is the first (not used to represent a range of characters). Otherwise, \- will do.
3) A word does only not contain white space characters
The regular expression for such a word is [^ \t]+
[^..] _____ is a container for any character that _won't_ match
__________ is simply a space character
\t ________ represents a Tab character
You can use the find/replace dialog to check if the regex will find the correct matches.
Make sure you use the following form:
^[a-zA-Z]+$
^ _________ indicates the start of a line
[a-zA-Z] __ use any regex to your liking
$ _________ indicates the end of a line
This will find lines you are looking for.
Now copy the correct regular expression to the Clipboard.
Now use to TextFX menu to achieve what you want.
Menu_____ : TextFX
Submenu__ : TextFX Viz Settings
Option___ : +Viz Text Search Regex
Check this option. You may have to check this twice, to be sure it is checked! (Check this by looking a third time there.)
Menu_____ : TextFX
Submenu__ : TextFX Viz
Option___ : Hide Lines with (Clipboard) Text
This will hide all lines containing only one word.
This may not work for the very first line of the document.
Press Ctrl+A to select all lines (including hidden lines).
1. Did you check the Regular Expression option in the Find/Replace dialog?
For the normal Ctrl+F/H dialog, it's a radio button in the bottom left corner. The third and last option in the Search mode group.
For the advanced Ctrl+R dialog, check the Regular Expr checkbox. It's the 4th checkbox on the right side of the dialog, just below the replace textbox.
Can you _find_ any line using one of those dialogs?
2. Did you check the Regular Expression option in the TextFX Viz Settings menu? If it is activated on startup, the check mark itself won't be visible. You have to (un)check it and check it once more, to make it appear.
If neither of this helps, then just copy the text of one of the lines you want to delete and use that as the regular expression (or Clipboard text).
I just performed the remove action on the complete text of your message. I ended up with one line being removed using the ^[a-zA-Z]+$ regular expression: the line containing the word "spousesfirstname".
The lines with the numbered spousesfirstnames won't be deleted. They contain digits, which are not part of the regular expression. If you want to delete those, you could try (just to check the working, use the find Dialog first) the following regex:
^[0-9a-zA-Z]+$
or
^[\da-zA-Z]+$
since
\d represents [0-9]
Does this get you any further?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
When I checked Menu, View, Show all characters, I noticed there was a trailing space behind the last word on all lines. I removed all trailing spaces and then your instructions worked!
Lesson learned, always view all characters first.
Thank you.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
if a line has only one word, how can I auto delete all lines containing only one word?
Why does the deleted text re-appear everytime I save and reopen?
I already tried 'delelete invisable selection'
ANSWER: Copy Visible Selection
Ask yourself this question: how would you define "word"?
Just a tip first to get some more information about the type of searching and replacing you are about to perform:
"RE: Need help using regex"
By: Fool4UAnyway (fool4uanyway) - 2008-04-23 19:22
http://sourceforge.net/forum/message.php?msg_id=4923889
Read the threads referenced there.
What are you about to do? Delete lines with only one word.
What is a word? Probably a consecutive string of non-space characters, although you may not want to include _any_ character:
1) A word only contains letters a to z and A to Z
2) A word contains other characters like -, _, / etc.
3) A word does only not contain white space characters
You can use either (Ctrl+F/H for regular or Ctrl+R for advanced) find and replace dialog, to test the regular expression (check that option!) you are about to use.
1) A word only contains letters a to z and A to Z
The regular expression for such a word is [a-zA-Z]+
[...] _____ is a container for any character that will match
a-z _______ means: any character a, z or in-between
+ _________ means: at least one match, but any other consecutive match will also be included
2) A word contains other characters like -, _, / etc.
You can add any other matching character between the square brackets.
The regular expression for such a word could be [-_a-zA-Z]+
I guess the - will be treated just as the - character if it is the first (not used to represent a range of characters). Otherwise, \- will do.
3) A word does only not contain white space characters
The regular expression for such a word is [^ \t]+
[^..] _____ is a container for any character that _won't_ match
__________ is simply a space character
\t ________ represents a Tab character
You can use the find/replace dialog to check if the regex will find the correct matches.
Make sure you use the following form:
^[a-zA-Z]+$
^ _________ indicates the start of a line
[a-zA-Z] __ use any regex to your liking
$ _________ indicates the end of a line
This will find lines you are looking for.
Now copy the correct regular expression to the Clipboard.
Now use to TextFX menu to achieve what you want.
Menu_____ : TextFX
Submenu__ : TextFX Viz Settings
Option___ : +Viz Text Search Regex
Check this option. You may have to check this twice, to be sure it is checked! (Check this by looking a third time there.)
Menu_____ : TextFX
Submenu__ : TextFX Viz
Option___ : Hide Lines with (Clipboard) Text
This will hide all lines containing only one word.
This may not work for the very first line of the document.
Press Ctrl+A to select all lines (including hidden lines).
Menu_____ : TextFX
Submenu__ : TextFX Viz
Option___ : Delete Invisible Selection
This should do.
After about ten tries, the instruction that you have detailed did not work. Altough I learned a great deal of useful information.
Here is the message I receive after executing your instructions;
'I'm not goint to hide all of the lines. Copy something to the clipboard that can be found.'
What I have copied to the clipboard is ^[a-zA-Z]+$
I tired both following your instructions and following your instructions after 'selecting all'
In the advance find/replace dialog, ^[a-zA-Z]+$ was not succesfull either.
The following is an example of several thousands of lines (obtained via OCR);
<example>
firstname1, lastname1
spousesfirstname
1 rodeo drive
somewhere, CA 90210
firstname2, lastname2
spousesfirstname2
2 rodeo drive
somewhere, CA 90210
firstname3, lastname3
spousesfirstname3
3 rodeo drive
somewhere, CA 90210
</example>
I want to eliminate the one-word spouse (which is not always present).
Thank you.
1. Did you check the Regular Expression option in the Find/Replace dialog?
For the normal Ctrl+F/H dialog, it's a radio button in the bottom left corner. The third and last option in the Search mode group.
For the advanced Ctrl+R dialog, check the Regular Expr checkbox. It's the 4th checkbox on the right side of the dialog, just below the replace textbox.
Can you _find_ any line using one of those dialogs?
2. Did you check the Regular Expression option in the TextFX Viz Settings menu? If it is activated on startup, the check mark itself won't be visible. You have to (un)check it and check it once more, to make it appear.
If neither of this helps, then just copy the text of one of the lines you want to delete and use that as the regular expression (or Clipboard text).
I just performed the remove action on the complete text of your message. I ended up with one line being removed using the ^[a-zA-Z]+$ regular expression: the line containing the word "spousesfirstname".
The lines with the numbered spousesfirstnames won't be deleted. They contain digits, which are not part of the regular expression. If you want to delete those, you could try (just to check the working, use the find Dialog first) the following regex:
^[0-9a-zA-Z]+$
or
^[\da-zA-Z]+$
since
\d represents [0-9]
Does this get you any further?
Success.
When I checked Menu, View, Show all characters, I noticed there was a trailing space behind the last word on all lines. I removed all trailing spaces and then your instructions worked!
Lesson learned, always view all characters first.
Thank you.
Why does the deleted text re-appear everytime I save and reopen?
I already tried 'delelete invisable selection'
In case there are any space characters just before and/or after the "only" word on the line, use the following regex:
^ *[a-zA-Z]+ *$
* _____ means any consecutive string of space characters will match, but none needed.
You can visibly check the presence of white space characters by checking the Show all characters option in the View menu.