Learn Practice Daily golf Reference
Search·Lesson 5 of 6·9 min·0/6 exercisesPro

Patterns

Tune the detector finer: . is any character, \d a digit, \< and \> word edges, \c any case, and \zs puts the cursor on the part of the match you want.

Scene

Monday, 2:20 p.m. The rider logs from Friday: twenty-four stops, one per line. Eight of them, every order Friday's override touched, have the latitude and the longitude swapped, and in Miami a latitude is never negative. Searching for 25 beeps at every latitude, good and bad alike.

What you need to say is a latitude that starts with a minus. The detector has finer settings than a word.

From memory

Warm-up from earlier chapters

Two from earlier chapters, from memory, before the new idea. Two wrong tries show the answer.

Search for order, landing on its last letter.
press the keys…9 keys
1 of 2
Search for order, landing on its last letter.

Any coin at all

In a search, a few characters are settings rather than letters. The most common is ., which matches any character: /2.5 finds 2.5, but also 205 and 2x5. When you mean a real dot, put a backslash before it: /2\.5.

Check yourself

Which one beeps first?

1fee: 205, avg: 2.5
NORMAL
Keys pressed: /2.5↵

You search with /2.5 and ↵. Where does the cursor land?

Pick an answer (or press its number), then watch the engine prove it.

Kinds of character

Some settings beep for a kind of coin rather than one coin: \d matches any digit and \s any space or tab, so /lat: \d finds a latitude that starts with a digit. \< and \> only beep for whole coins, marking the edges of a word: /\<lat\> finds lat but not latitude, which is exactly what * searches for.

Check yourself

Just a minus?

1// rider logs, Friday: one stop per line
1export const STOPS = [
2 { stop: 1041, zone: "Little Havana", lat: 25.7656, lng: -80.219 },
3 { stop: 1044, zone: "Edgewater", lat: 25.8001, lng: -80.1887 },
4 { stop: 1047, zone: "Downtown", lat: -80.1937, lng: 25.7743 },
5 { stop: 1050, zone: "Coral Way", lat: 25.7505, lng: -80.2409 },
NORMAL
Keys pressed: /-↵

A swapped stop has a minus in its latitude. You search for just - from the top of the log. Where is the first match?

Pick an answer (or press its number), then watch the engine prove it.

Stand on the part you want

\zs says the match starts here: everything before it has to be there, but the cursor lands after it. /lat: \zs- finds a latitude that starts with a minus and puts the cursor on the minus. (\ze does the same for the end.)

1// rider logs, Friday: one stop per line
1export const STOPS = [
2 { stop: 1041, zone: "Little Havana", lat: 25.7656, lng: -80.219 },
3 { stop: 1044, zone: "Edgewater", lat: 25.8001, lng: -80.1887 },
4 { stop: 1047, zone: "Downtown", lat: -80.1937, lng: 25.7743 },
5 { stop: 1050, zone: "Coral Way", lat: 25.7505, lng: -80.2409 },
6 { stop: 1053, zone: "Wynwood", lat: 25.8005, lng: -80.1994 },
7 { stop: 1056, zone: "Brickell", lat: -80.1917, lng: 25.7663 },
8 { stop: 1059, zone: "Little Havana", lat: 25.7656, lng: -80.219 },
9 { stop: 1062, zone: "Edgewater", lat: -80.1887, lng: 25.8001 },
10 { stop: 1065, zone: "Downtown", lat: 25.7743, lng: -80.1937 },
11 { stop: 1068, zone: "Coral Way", lat: 25.7505, lng: -80.2409 },
12 { stop: 1071, zone: "Wynwood", lat: -80.1994, lng: 25.8005 },
13 { stop: 1074, zone: "Brickell", lat: 25.7663, lng: -80.1917 },
14 { stop: 1077, zone: "Little Havana", lat: 25.7656, lng: -80.219 },
15 { stop: 1080, zone: "Edgewater", lat: -80.1887, lng: 25.8001 },
16 { stop: 1083, zone: "Downtown", lat: 25.7743, lng: -80.1937 },
17 { stop: 1086, zone: "Coral Way", lat: -80.2409, lng: 25.7505 },
18 { stop: 1089, zone: "Wynwood", lat: 25.8005, lng: -80.1994 },
19 { stop: 1092, zone: "Brickell", lat: 25.7663, lng: -80.1917 },
20 { stop: 1095, zone: "Little Havana", lat: -80.219, lng: 25.7656 },
21 { stop: 1098, zone: "Edgewater", lat: 25.8001, lng: -80.1887 },
22 { stop: 1101, zone: "Downtown", lat: 25.7743, lng: -80.1937 },
23 { stop: 1104, zone: "Coral Way", lat: -80.2409, lng: 25.7505 },
24 { stop: 1107, zone: "Wynwood", lat: 25.8005, lng: -80.1994 },
25 { stop: 1110, zone: "Brickell", lat: 25.7663, lng: -80.1917 },
26];
NORMALLoading the editor…1:1
Try it

Find the swaps

Land on the minus of the first four negative latitudes, top to bottom. One pattern with \zs, then n.

1 of 4Move the cursor onto the
1// rider logs, Friday: one stop per line
1export const STOPS = [
2 { stop: 1041, zone: "Little Havana", lat: 25.7656, lng: -80.219 },
3 { stop: 1044, zone: "Edgewater", lat: 25.8001, lng: -80.1887 },
4 { stop: 1047, zone: "Downtown", lat: -80.1937, lng: 25.7743 },
5 { stop: 1050, zone: "Coral Way", lat: 25.7505, lng: -80.2409 },
6 { stop: 1053, zone: "Wynwood", lat: 25.8005, lng: -80.1994 },
7 { stop: 1056, zone: "Brickell", lat: -80.1917, lng: 25.7663 },
8 { stop: 1059, zone: "Little Havana", lat: 25.7656, lng: -80.219 },
9 { stop: 1062, zone: "Edgewater", lat: -80.1887, lng: 25.8001 },
10 { stop: 1065, zone: "Downtown", lat: 25.7743, lng: -80.1937 },
11 { stop: 1068, zone: "Coral Way", lat: 25.7505, lng: -80.2409 },
12 { stop: 1071, zone: "Wynwood", lat: -80.1994, lng: 25.8005 },
13 { stop: 1074, zone: "Brickell", lat: 25.7663, lng: -80.1917 },
14 { stop: 1077, zone: "Little Havana", lat: 25.7656, lng: -80.219 },
15 { stop: 1080, zone: "Edgewater", lat: -80.1887, lng: 25.8001 },
16 { stop: 1083, zone: "Downtown", lat: 25.7743, lng: -80.1937 },
17 { stop: 1086, zone: "Coral Way", lat: -80.2409, lng: 25.7505 },
18 { stop: 1089, zone: "Wynwood", lat: 25.8005, lng: -80.1994 },
19 { stop: 1092, zone: "Brickell", lat: 25.7663, lng: -80.1917 },
20 { stop: 1095, zone: "Little Havana", lat: -80.219, lng: 25.7656 },
21 { stop: 1098, zone: "Edgewater", lat: 25.8001, lng: -80.1887 },
22 { stop: 1101, zone: "Downtown", lat: 25.7743, lng: -80.1937 },
23 { stop: 1104, zone: "Coral Way", lat: -80.2409, lng: 25.7505 },
24 { stop: 1107, zone: "Wynwood", lat: 25.8005, lng: -80.1994 },
25 { stop: 1110, zone: "Brickell", lat: 25.7663, lng: -80.1917 },
26];
NORMALLoading the editor…1/40.0s1:1

This exercise needs a keyboard. Read on, and play it at your computer.

Any case, fewer backslashes

\c anywhere in a pattern tells the detector to ignore case: /\corder finds Order and ORDER too. And \v at the start (very magic) is a simpler dial: it lets parentheses, braces, + and ? work without backslashes: /\v\d+ instead of /\d\+. Handy once patterns get long.

From memory

Settings, from memory

Press the keys.

Search for order as a whole word only.
scroll here, then press the keys11 keys
1 of 4
Search for order as a whole word only.
Boss round

All eight

Every swapped stop in the rider logs, top to bottom: land on the minus of each negative latitude. This time you start at the end of the file, and the pattern is yours to write. Count them as you go.

Stuck? Show a hint
Pro
The rest of this lesson is in Pro

The first exercise of every lesson is free. Pro unlocks the rest, every track, for good.

See Pro

This exercise needs a keyboard. Read on, and play it at your computer.