Stephen Marsh
Well-known member
I am looking for advice and help with GREP find replace. I am wishing to delete all text and wordspaces in a sentence, EXCEPT for one single key bit of text:
INPUT =
2A - 4x12! - some More tEXT and now the keyword (1) etc $
Z3 - 9-1* some random text and now the new_keyword {88} etc %
OUTPUT =
keyword
new_keyword
As you can see, there are multiple characters, numbers, caps and lowercase, $pecial characters etc. All I wish to do is find the keyword and the new_keyword, retain them both and then delete everything else.
Of course, the unwanted text is not consistent and neither is the keyword, so I am expecting to have to run multiple GREP search and replace commands to clean up the text. Obviously there are many lines of text where I wish to clean things up to only retain the two keywords in question.
Is it possible to search for and retain multiple keywords, while removing everything else?
Can anybody point me to the regular expression/s that are needed? I can handle removing word spaces if I have to, what I am really after is how to single out two consistent single keywords, retain them and remove everything else (except for the CR/hard return at the end of each line).
I guess another way of looking at this is to find and select a keyword, invert the selection and delete and then repeat again on a line by line basis, keeping the return at the end of the original paragraph.
I will be using GREP capable software such as InDesign CS5 and/or TextWrangler.
Stephen Marsh
INPUT =
2A - 4x12! - some More tEXT and now the keyword (1) etc $
Z3 - 9-1* some random text and now the new_keyword {88} etc %
OUTPUT =
keyword
new_keyword
As you can see, there are multiple characters, numbers, caps and lowercase, $pecial characters etc. All I wish to do is find the keyword and the new_keyword, retain them both and then delete everything else.
Of course, the unwanted text is not consistent and neither is the keyword, so I am expecting to have to run multiple GREP search and replace commands to clean up the text. Obviously there are many lines of text where I wish to clean things up to only retain the two keywords in question.
Is it possible to search for and retain multiple keywords, while removing everything else?
Can anybody point me to the regular expression/s that are needed? I can handle removing word spaces if I have to, what I am really after is how to single out two consistent single keywords, retain them and remove everything else (except for the CR/hard return at the end of each line).
I guess another way of looking at this is to find and select a keyword, invert the selection and delete and then repeat again on a line by line basis, keeping the return at the end of the original paragraph.
I will be using GREP capable software such as InDesign CS5 and/or TextWrangler.
Stephen Marsh
Last edited: