2828Programming ((tool))s and techniques survive and spread in a chaotic,
2929evolutionary way. It's not always the pretty or brilliant ones that
3030win but rather the ones that function well enough within the right
31- niche or happen to be integrated with another successful piece of
31+ niche or that happen to be integrated with another successful piece of
3232technology.
3333
3434{{index "domain-specific language"}}
@@ -50,7 +50,7 @@ expressions will make you a more effective programmer.
5050
5151{{index [ "regular expression", creation] , "RegExp class", "literal expression", "slash character"}}
5252
53- A regular expression is a type of object. It can either be constructed
53+ A regular expression is a type of object. It can be either constructed
5454with the ` RegExp ` constructor or written as a literal value by
5555enclosing a pattern in forward slash (` / ` ) characters.
5656
@@ -313,7 +313,7 @@ console.log(match.index);
313313An object returned from ` exec ` has an ` index ` property that tells us
314314_ where_ in the string the successful match begins. Other than that,
315315the object looks like (and in fact is) an array of strings, whose
316- first element is the string that was matched—in the previous example,
316+ first element is the string that was matched. In the previous example,
317317this is the sequence of ((digit))s that we were looking for.
318318
319319{{index [ string, methods] , "match method"}}
@@ -362,14 +362,14 @@ extract it and construct an object that represents it, we can wrap
362362parentheses around the digit patterns and directly pick the date out
363363of the result of ` exec ` .
364364
365- But first, a brief detour, in which we discuss the built-in way to
365+ But first we'll take a brief detour, in which we discuss the built-in way to
366366represent date and ((time)) values in JavaScript.
367367
368368## The Date class
369369
370370{{index constructor, "Date class"}}
371371
372- JavaScript has a standard class for representing ((date))s—or rather,
372+ JavaScript has a standard class for representing ((date))s—or, rather,
373373points in ((time)). It is called ` Date ` . If you simply create a date
374374object using ` new ` , you get the current date and time.
375375
@@ -422,10 +422,10 @@ millisecond count by creating a new `Date` object and calling
422422
423423{{index "getFullYear method", "getMonth method", "getDate method", "getHours method", "getMinutes method", "getSeconds method", "getYear method"}}
424424
425- Date objects provide methods like ` getFullYear ` , ` getMonth ` ,
425+ Date objects provide methods such as ` getFullYear ` , ` getMonth ` ,
426426` getDate ` , ` getHours ` , ` getMinutes ` , and ` getSeconds ` to extract their
427427components. Besides ` getFullYear ` there's also ` getYear ` , which gives
428- you the year minus 1900 (` 98 ` or ` 119 ` ), and is mostly useless.
428+ you the year minus 1900 (` 98 ` or ` 119 ` ) and is mostly useless.
429429
430430{{index "capture group", "getDate function"}}
431431
@@ -444,7 +444,7 @@ console.log(getDate("1-30-2003"));
444444
445445{{index destructuring, "underscore character"}}
446446
447- The ` _ ` (underscore) binding is ignored, and used only to skip the
447+ The ` _ ` (underscore) binding is ignored and used only to skip the
448448full match element in the array returned by ` exec ` .
449449
450450## Word and string boundaries
@@ -518,10 +518,10 @@ each other to express a choice between more than two alternatives.
518518
519519{{index [ "regular expression", matching] , [ matching, algorithm] , searching}}
520520
521- Conceptually, when you use ` exec ` or ` test ` the regular expression
521+ Conceptually, when you use ` exec ` or ` test ` , the regular expression
522522engine looks for a match in your string by trying to match the
523523expression first from the start of the string, then from the second
524- character, and so on until it finds a match or reaches the end of the
524+ character, and so on, until it finds a match or reaches the end of the
525525string. It'll either return the first match that can be found or fail
526526to find any match at all.
527527
@@ -554,9 +554,9 @@ through the flow chart would look like this:
554554 single space character. There is a space here, not a digit, so we
555555 must take the second path.
556556
557- - We are now at position 6 (the start of "pigs" ) and at the three-way
558- branch in the diagram. We don't see "cow" or "chicken" here, but we
559- do see "pig" , so we take that branch.
557+ - We are now at position 6 (the start of _ pigs _ ) and at the three-way
558+ branch in the diagram. We don't see _ cow _ or _ chicken _ here, but we
559+ do see _ pig _ , so we take that branch.
560560
561561 - At position 9, after the three-way branch, one path skips the _ s_
562562 box and goes straight to the final word boundary, while the other
@@ -678,7 +678,7 @@ expression instead.
678678{{index grouping, "capture group", "dollar sign", "replace method", [ "regular expression", grouping] }}
679679
680680The real power of using regular expressions with ` replace ` comes from
681- the fact that we can refer back to matched groups in the replacement
681+ the fact that we can refer to matched groups in the replacement
682682string. For example, say we have a big string containing the names of
683683people, one name per line, in the format ` Lastname, Firstname ` . If we
684684want to swap these names and remove the comma to get a `Firstname
@@ -714,7 +714,7 @@ console.log(s.replace(/\b(fbi|cia)\b/g,
714714// → the CIA and FBI
715715```
716716
717- And here 's a more interesting one:
717+ Here 's a more interesting one:
718718
719719```
720720let stock = "1 lemon, 2 cabbages, and 101 eggs";
@@ -737,7 +737,7 @@ is decremented by one.
737737
738738The ` (\d+) ` group ends up as the ` amount ` argument to the function,
739739and the ` (\w+) ` group gets bound to ` unit ` . The function converts
740- ` amount ` to a number—which always works, since it matched ` \d+ ` —and
740+ ` amount ` to a number—which always works since it matched ` \d+ ` —and
741741makes some adjustments in case there is only one or zero left.
742742
743743## Greed
@@ -1037,7 +1037,7 @@ usually called an _INI_ file) are as follows:
10371037
10381038Our task is to convert a string like this into an object whose
10391039properties hold strings for settings written before the first
1040- section header and sub-objects for sections, with those sub-objects
1040+ section header and subobjects for sections, with those subobjects
10411041holding the section's settings.
10421042
10431043{{index "carriage return", "line break", "newline character"}}
@@ -1137,7 +1137,7 @@ whitespace, including things like the ((nonbreaking space)) and the
11371137
11381138Another problem is that, by default, regular expressions work on code
11391139units, as discussed in [ Chapter ?] ( higher_order#code_units ) , not
1140- actual characters. This means that characters that are composed of two
1140+ actual characters. This means characters that are composed of two
11411141code units behave strangely.
11421142
11431143```
@@ -1181,7 +1181,7 @@ Unicode defines a number of useful properties, though finding the one
11811181that you need may not always be trivial. You can use the
11821182` \p{Property=Value} ` notation to match any character that has the
11831183given value for that property. If the property name is left off, as in
1184- ` \p{Name} ` , the name is assumed to either be a binary property such as
1184+ ` \p{Name} ` , the name is assumed to be either a binary property such as
11851185` Alphabetic ` or a category such as ` Number ` .
11861186
11871187{{id summary_regexp}}
@@ -1354,7 +1354,7 @@ if}}
13541354{{index "quoting style (exercise)", boundary}}
13551355
13561356The most obvious solution is to replace only quotes with a nonword
1357- character on at least one side. Something like ` /\W'|'\W/ ` . But you
1357+ character on at least one side—something like ` /\W'|'\W/ ` . But you
13581358also have to take the start and end of the line into account.
13591359
13601360{{index grouping, "replace method"}}
@@ -1373,7 +1373,7 @@ hint}}
13731373
13741374Write an expression that matches only JavaScript-style ((number))s. It
13751375must support an optional minus _ or_ plus sign in front of the number,
1376- the decimal dot, and exponent notation—` 5e-3 ` or ` 1E10 ` — again with an
1376+ the decimal dot, and exponent notation—` 5e-3 ` or ` 1E10 ` —again with an
13771377optional sign in front of the exponent. Also note that it is not
13781378necessary for there to be digits in front of or after the dot, but the
13791379number cannot be a dot alone. That is, ` .5 ` and ` 5. ` are valid
0 commit comments