The output of "perldoc perlre" (or "man perlre" on unix) is lengthy (and rather dense in spots), but well worth whatever time you can devote to read and understand it. It will explain the syntax: what the square brackets mean inside a regex, why the positioning of a hyphen inside square brackets is very important, when you need to use a backslash to "escape" a character (in square brackets or elsewhere in the regex), and when you don't need to use it.
For parts that seem hard to decipher, play with the examples that are provided; try variations on the examples to see what happens; perl one-liners on a command line are very handy for this:
perl -e '$_ = "test-string"; print "okay\n" if (/[-st]{5}/)'
# that should print "okay"
perl -e '$_ = "test-string"; print "okay\n" if (/[s\-t]{5}/)'
# should do the same
perl -e '$_ = "test-string"; print "okay\n" if (/[s-t]{5}/)'
# prints nothing: regex didn't match
perl -e '$_ = "test-string"; print "okay\n" if (/[t-s]{5}/)'
# prints an error message: "Invalid [] range "t-s" in regex...
... and so on. It all makes sense when you RTFM.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.