Errata

Mastering Regular Expressions

Errata for Mastering Regular Expressions

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.

Color Key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted by Date submitted
52
Middle

$price =~ s/(\.\d\d[1-9]?)d*/$1/

Should be:

$price =~ s/(\.\d\d[1-9]?)\d*/$1/

That is made clear a little farther down the page.near the bottom of the next paragraph after the code example shown above.

Jon S.  Dec 09, 2013 
Printed Page 70
second "$text" substitution and explanation

$text =~ s/^\s*$/<p>/mg;

Given $text as "with.\n\n\n\t \nTherefore", this will correctly produce only one "<p>" due to the form of the string.

The general problem can be seen in this Perl program:
my $text = "A\nB\n\nC\n\n\nD\n\n\n\nE\n\n\n\t F";
$text =~ s/^\s*$/<p>/mg;
print $text;

A simple fix* would be to follow the first substitution with:
$text =~ s/<p><p>/<p>/g;
*However, the whitespace before "F" would still be in $text.

Gregory Sherman  Jul 06, 2022 
Printed Page 70
second "$text" substitution and explanation

The problem of duplicate <p> tags can also be solved with one substitution:

1 while $text =~ s/^\s*$/<p>/m;

Gregory Sherman  Jul 08, 2022 
77
Top

The first regex for "That Double-Word Thing" is displayed as (note the double '<'):
\b([a-z]+)((?:\s<<[^>]+>)+)(\1\b)

It should be:
\b([a-z]+)((?:\s|<[^>]+>)+)(\1\b)

It is corrected in the later example using the multi-line regex.

Jon S  Dec 09, 2013 
Printed, PDF Page 162
4th marked regex

The closing parenthesis ) after the "end of regex" mark is not inside the regex but should be inside.

Julian R.  Sep 14, 2013 
Printed Page 167
Regex example after 2nd paragraph and the next regex example after 3rd paragraph

Book gives <B>((?!<B>).)*?</B> (first Regex on p. 167, after 2nd paragraph), while this gives a full match of <B>zillions</B>, it only captures the s in zillions

Same issue with the alternate <B>((?!</?B>).)*</B> (second Regex on p. 167, after 3rd paragraph), it gives a full match of <B>zillions</B>, it only captures the s in zillions (second Regex on p. 167)

Either <B>((?:(?!<B>).)*)</B> (greedy) or <B>((?:(?!<B>).)*?)</B> (non-greedy) seems to both match all of <B>zillions</B> and captures the entire word zillions


Example on regex101.com
https://regex101.com/r/jHDqRK/1/

Eric Dorsey  Feb 07, 2020 
Printed Page 187
2 regexes in top section and text

^\w+=[^\n\\]*(\\n[^\n\\]*)*

"... disallowed backslashes other than those at the end of lines."

Actually, anything (or nothing) after a "word" followed by an equal sign will match.
The parentheses do not capture anything useful.

These statements also apply to the next regex:

^\w+=([^\n\\]|\\.)* "in a dot-matches-all mode"

It can be modified to require a backslash at the end of continuation lines.
The perl code below disposes of backslashes and backslash-character sequences
after capturing the values in $1.

my $src = 'SRC=array.c\tbuiltin.c math.c \
args.c \ string.c\
time.c';

if ($src =~ m/^\w+=((?:[^\n\\]|\\.)*)$/s)
{
my @v = split /\s+/, $1 =~ s/\\./ /grs;
print "[@v]\n";
}

Gregory Sherman  Jan 26, 2020 
Printed Page 270
regex at bottom of page

This one is presented as a faster solution to the continuation-line problem.
The regex captures the values after the equals sign, but again matches any string that starts with \w+=
It is, in effect, a slower and more complex version of (in perl) /^\w+=(.*)/s

Gregory Sherman  Jan 26, 2020 
Printed Page 336
first code block and following text

"... when applied to '123 abc 73xyz' it's left with a value of two ..."

Running the code block with the string above in $text, $Count becomes 3

Gregory Sherman  Jan 26, 2020 
Printed Page 339
run explanations

"... if we invoke the exact same call again, the second time shows:
The whole match ..."

I get the exact same output - "The optimizer started the match at character 5." -
on both runs (perl 5.30).

Gregory Sherman  Jan 26, 2020