Patterns in the Find Bar

bridgeyman

macrumors member
Original poster
Mar 16, 2008
42
0
Here is a cool feature I wanted to share!

The new find bar in Lion is very powerful. Check it out in TextEdit. It supports pattern tokens to search for complex expressions (like an email address, or a number) or characters that are difficult to type (like tab or line break). Using them with the replace feature allows you to easily reformat data.

To access the patterns, click on the magnifying glass on the text field, and then choose "Insert Pattern". The keyboard shortcut is useful here.



Here you can insert tokens for characters that were hard to search for before, like a tab or a line break.



What is more useful are the smarter tokens. Enter the "Email Address" token, and it will match text that looks like an email address. With the building block tokens you can create some neat expression. Here I have a list of names.

1. Ted J. Rozar
2. Julio Scriven
3. Eve Gongora
4. Nelson Gerhard
5. Max K. Becerril
6. Javier Duguay
7. Jessie Fedele
8. Trimarchi Colin Kai
9. Neva Gunderman
10. Gay Linley
11. Javier James Seto
12. Maricela Langan
13. Katherine Soo
14. Lonnie Glimmer
15. Carmella Liebold
16. Tyrone L. Perino
17. Carlene Stalky
18. Kurt Georges
19. Kenya Lion Willits
20. Clare Tome

Some of them have middle names, some have middle initials. Some have three spaces after the number, some have one. The following pattern matches a line of these names:



The expression is (Digits).(whitespace)(Any Characters)(whitespace)(Word Characters)(Line Break)

The (any characters) matches the first name, and even will match the middle name. The (word characters) surrounded by white space and a line break can only match the last name.

Notice that many of them are different colors. This is so you recognize each token, and use it in replace! If you have more than one of the same type of pattern they will be numbered, like the white space characters in this example. Say we want to rearrange this list so it looks like this:
1: Lastname, Firstname Middle
(Notice the tab after the number).

I check "replace" to enable the replace field. Now when I insert tokens, I can choose from tokens that are already in the find field. Here is an expression I made:



Notice that is uses most of the same tokens, but in different order. The colors are the same. Now you can replace each line individually, or just hit replace all and your data will be reformatted!

Here is the data after reformatting:
1: Rozar, Ted J.
2: Scriven, Julio
3: Gongora, Eve
4: Gerhard, Nelson
5: Becerril, Max K.
6: Duguay, Javier
7: Fedele, Jessie
8: Kai, Trimarchi Colin
9: Gunderman, Neva
10: Linley, Gay
11: Seto, Javier James
12: Langan, Maricela
13: Soo, Katherine
14: Glimmer, Lonnie
15: Liebold, Carmella
16: Perino, Tyrone L.
17: Stalky, Carlene
18: Georges, Kurt
19: Willits, Kenya Lion
20: Tome, Clare

I hope this is useful for people! Try out this example. What do you think? When developers adopt the new Cocoa find bar, this advanced searching comes for free. Hopefully it will be all over the OS soon, not just in TextEdit.

- Bridger Maxwell
 
Last edited:

gregmaletic

macrumors newbie
Jul 22, 2011
1
0
> The new find bar in Lion is very powerful.

By "find bar", do you mean the find field in a Finder window? If so, mine doesn't look like the one you picture. There's no little down-arrow, so no pop-up appears when I click on the magnifying glass.

What am I missing?

Thanks.
 
Comment

guitargoddsjm

macrumors 6502
Feb 25, 2008
389
0
MA
> The new find bar in Lion is very powerful.

By "find bar", do you mean the find field in a Finder window? If so, mine doesn't look like the one you picture. There's no little down-arrow, so no pop-up appears when I click on the magnifying glass.

What am I missing?

Thanks.
I'm wondering the same thing...
 
Comment

tkermit

macrumors 68040
Feb 20, 2004
3,435
2,428
Look for it in TextEdit. It's really pretty awesome. Thanks, Bridger!
 
Comment

bridgeyman

macrumors member
Original poster
Mar 16, 2008
42
0
Woops, I did forget to say this example was in TextEdit. However, this functionality is now provided in the Cocoa framework, so developers can very easily add it to their own apps, thanks to the work of kpua.
 
Last edited:
Comment

Similar threads

Register on MacRumors! This sidebar will go away, and you'll see fewer ads.