I realized ... as soon as I saw it posted on the internet. I swear I have a better critical eye under that circumstance than I do my own screen sometimes.
A well known phenomenon. :-) Cf. Re: Move along, nothing to see here . . . and its two follow-ups, and Rubber_duck_debugging.
...can you explain these substitutions, in particular, the values chosen.
Nothing clever here. When I ran the code without substitutions, certain character entities failed to render correctly (on my Windows 8.1 system, in which the command window’s code page happens to be set to 1252). So I looked at the original as rendered in Google Chrome to determine what the entities were supposed to be, then wrote the substitutions accordingly. Of course, YMMV.
How is the action of s defined, and why does this one not have 3 matched symbols after it?
Substitution performs a regular expression match against the first half (LHS), and then, if a match is found, substitutes the second half (RHS) for whatever was matched. See “s/PATTERN/REPLACEMENT/msixpodualngcer” under perlop#Regexp-Quote-Like-Operators.
When choosing delimiters for a regular expression, you have a choice between bracketing (paired) and non-bracketing (unpaired) symbols. If you choose a non-bracketing delimiter — such as /, !, or # — you use that delimiter twice for a regex and three times for a substitution:
$x =~ m!\d+\s*\w+!; # Note that the "m" prefix is required except w +hen the delimiter is "/" $x =~ s!\d+\s*\w+!_!;
However, if you choose bracketing delimiters — (), [], {}, or <> — then a regex has one matching pair of delimiters, and a substitution has two pairs, or four symbols in total:
$x =~ m[\d+\s*\w+]; $x =~ s[\d+\s*\w+][_];
When delimiters are paired, they have to match each other; but in a substitution the second pair does not have to match the first pair. See perlop#Quote-and-Quote-like-Operators.
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re^9: regex to get random quote
by Athanasius
in thread regex to get random quote
by Aldebaran
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |