Pages has a pretty basic text search function, but with a few hidden tricks. TextEdit has a more robust pattern matching system and can even reorder text using replacements.
You can also watch this video at YouTube.
Watch more videos about related subjects: Pages (226 videos), TextEdit (28 videos).
You can also watch this video at YouTube.
Watch more videos about related subjects: Pages (226 videos), TextEdit (28 videos).
Video Transcript
Hi, this is Gary with MacMost.com. Let me show you some advanced text search techniques in Pages and TextEdit.
MacMost is brought to you thanks to a great group of more than 1000 supporters. Go to MacMost.com/patreon. There you can read more about it. Join us and get exclusive content and course discounts.
Now searching for text in an app like Pages is pretty straight forward. In Pages you would go to Edit, then Find, and then use Find or simply the keyboard shortcut Command F. This brings up the Find & Replace box here and you could type in it and look for something. So, for instance, if I look for a word that I see here, you can see I type it and it finds all of the incidences of that word. I can use the arrows here to move back and forth between them. But it shows me all the ones it finds and gives me a count right here. I can also type something in here in Replace and replace all incidences of it or I can replace the one that is selected and find the next one or just replace that one and stay there. So those are the basics.
Now what happens if I want to search for something like a return or a new paragraph or new line. Whatever you want to call it. Like this character here. How would I search for that? Well, there's a special key sequence that you can type, a kind of a secret feature. You type Backslash, that's backslash not forward slash so on US keyboards it is the key just below the Delete key and above the Return key. Then you use N, it is actually going to search for New Line characters. So you can see it find every new line character here. In fact if I were to search for N and then N again it's going to find incidences where there is an extra line. Like right here.
Now there is another special character you can type. That's Backslash T. That will search for Tab characters. You can see I've got one here in the middle of this paragraph and I've also got some columned data here where I've put some tabs so it will find those. It finds a total of five of those.
There are a few other things that you can do in Pages. One is that you can set it for Match Case or Not. So if I check Match Case and I search for this word you could see it comes up with 3 of them. It doesn't include this one right here because I have matched case turned on and that has a capital letter in it. If I turn off Match Case now you can see it is going to find 4 of them including this one. Another thing you could use is whether to look for whole words or not. So with that Off I can search for this and it is going to find even the beginnings of words or parts of the insides of words that have those three characters. But if I say Whole words then it is only going to return results where that is the entire word. There aren't other letters before or after it.
There is on other special thing that it does when you're searching. Alternative characters, like for instance the different types of quotes, curly quotes, left, right, straight quotes and apostrophes, all can be found if you just search for Quotes. So if I search for a quote like that you can see it is going to find the left curly quote, the right curly quote, and the straight quotes as well. The same thing if I search for apostrophes. It will find them whether they are straight, the left one or the right one.
Now I want to show you a couple of practical techniques here. One is that you may want to search for when you've accidentally added two spaces instead of one. You can do that using a regular search and just put two spaces here. It is actually going to locate all the incidences of two spaces. So you can see them all here. Then you could replace with one space. So I'll just do Replace All and now I've got no incidences left where there are two spaces. Likewise as I showed before you can do an extra Return, like here is a blank line, by looking for two N's. Then you could replace that with one N, like that, I'll Replace All and now I've removed all of the blank lines.
That's really all the advanced search functionality you've got in Pages. But it is a different story when it comes to TextEdit. So here is a TextEdit window. I've got it set to Plain Text but this works in Rich Text Mode as well. Now when you search here use the same Command, so Edit, Find, Find or Command F. That actually puts the search in the top of the window here, not as a separate little window. Now you can search for regular things here. So, for instance, I can just search like that and it finds all incidences of those combinations of that word. You've also got the ability here to ignore case. So if I turn this Off notice how it doesn't find this one here because there is a capital letter in it. I can also wrap around, in other words as I use these arrows here when I get to the end it goes back to the beginning.
But I also have the ability to use kind of a wild card type functionality where I can say, I want words that either contain this, start with this, or the full word has to be this. So if I say Contains I get everything. But if I say Starts With you can see I no longer get this one, for instance, or this one because those letters are in the middle of that word. I could also say just Full Word and it will show me only ones that have just those letters, exactly that. I can also search for invisible characters, like new lines and tabs. But I can't do backslash N or backslash T here. That doesn't work. Instead click on the little magnifying glass here and go to Insert Pattern. Now I can say look for Line Breaks, like this and it says we will find 14 of them. It doesn't do a really good job of showing you those. But you could, for instance, look for an extra one like this. So I'll Insert Pattern and add another line break and you could see it's found 3. So that one there, and that one there, and that one there. I could check Replace here and I can instead replace it with just one. So if I were to use this with the All button here, you can see how it gets rid of those extra lines.
But you can see there is a whole bunch of different things that are Insert Pattern. Note the keyboard shortcut to make things a lot easier than having to select this menu all the time. So we could, for instance, look for any word characters. So this will actually find words. So you can see it selected every word individually in here. I can also look for Digits. So to select only digit characters. I could also look for things like an email address and you can see it selects all the email addresses in the document. There is also an URL and a phone number. Notice how well the phone number works. It actually selects all of these in these different phone number formats.
For even more advanced functionality you can combine these. So, for instance, I can use the keyboard shortcut here and then I'm going to say I want to look for Digits and then I'm going to look for Comma, and then another set of Digits. So you can see these three things match that. But other numbers, like this, don't match that. I could say I want to look for Digits and then any word characters. I'm going to get words that start with a digit. So it even includes this one which has a digit and then a bunch of letters. I can look for patterns. So for instance i've got this List here. Let's say I want to look for anything that has got this pattern, which would be a word followed by a white space, followed by another word followed by white space again followed by an email address. You can see how I just get things that fit that pattern. Notice there is also one here in the text. So if I wanted to I could add a line break after this and now it would only include these lines here.
Now notice here what is put as a pattern is word one and word two. The reason it does that because you could actually use this in the replacement. I could recreate each line here by using this same insert pattern as I was doing before but in the replacement. So I'll do Insert Pattern and notice that it's got all of the parts here represented here. So I could say let's start each line with the email address. Then I'm going to go and insert a tab. I'm going to use the keyboard shortcut here and say let's take word two, which would be the last name and then I'm going to do a comma and a space and then insert the word one, which is the first name. Then, because I'm also looking for this return character here, I'll make sure I include it here, line break. So now when I do Replace All look what happens to these five lines. Replaces them with that and this is a tab here. So this now might be ready to import into some sort of database.
Another thing you could do is you could look for certain patterns and maybe change the lines to indicate that they are there. For instance let's look for any word, then any white space like this, and then Smith. You could see it is going to find the line that have a first name and then Smith. Then let's continue with some white space and then an email address, and then what we're going to do is we're going to select all of that and place it into Replace here. You can see how it copies it all nicely. I didn't have to repopulate it word for word. Now what I can do here is a space and I'm going to use the fn and E key here to bring up the Emoji & Special Character Viewer. Look for some sort of nice left arrow, like this, and insert that. What this will do is take every first name and last name combination where the second part is Smith and an email address. Replace it with the same thing but put this little arrow there. So I do All and now you can see I've got nice little indicators here showing me exactly where all the Smith's are located. I could, later on, simply erase it by selecting this, pasting it in here and then replacing it with nothing and now it removes it and I maybe ready to look up another set of names.
So that is just a sampling of what you can do. There is so much you can do here using just these few simple special patterns of what you search for and what you can replace them with. Take the time to experiment with a sample document in TextEdit to see how this advanced Find & Replace functionality could help you in your work.
I have to keep in mind that almost no one whom I have encountered needs that level of complexity, and introducing it to them only creates confusion in their minds - TMI (too much information). Still, this needs to be put out there.
You did a good job demonstrating the advanced features of Find and Replace.
Thanks for the video. For so long I've been using a Windows freeware called Metapad, because it used the \n, \t wildcards. And in MS Word I use ^p, ^t. Now that I am mostly Mac based, I was disappointed that these options didn't work in TextEdit. I didn't think to try the Insert Pattern option. Thanks again. Jak.
Thank you very much for this insight Gary.
I think this would be very useful in my case when I have to copy a table from PDF or even as text from an image, and need to paste it into Numbers. I can see that placing the text into TextEdit first, for tidying up the format into a clean csv or tsv file by removing double spaces and converting these to tabs plus adding line breaks at the end of each line. Very useful, time saving and robust when you have to deal with a large table.
I hope I can find the bookmark I’m going to create for this when I need it. :)
Serendipity! Just came across Gary’s revelation of TextEdit Insert Pattern on the day I need to edit a machine-generated text file into a human-readable report. This happens every six months or so when I have to struggle to remember my REGEXP (Regular Expressions) syntax. This is going to save me so much time!