I think that perldoc perlre as a reference and perldoc perlretut as a tutorial for regular expressions work well. If you want a book that goes far beyond this, have a look at Mastering Regular Expressions, although I don't know how good it is at introducing regular expressions.

Some pointers to get you started on your homework:

  1. A match can be naively negated in two ways:
    if ($item !~ /foo/) {}; if (! $item =~ /foo/) {};
    Experiment with these to find the solution for the first exercise.
  2. For removing the first char of a string, perlfunc -f substr might be of interest, but as you want to limit yourself to regular expressions, the substitution operator s/// will be of interest to you. perldoc -f split might also be a way to a solution, but you will also need perldoc -f join to complete that way.
  3. This is a hard problem to solve with regular expressions for someone new to REs. I would use one of the prefabricated modules for parsing CSV strings, but if you really want to go down the road of parsing CSV with regular expressions, approach the problem in the following fashion:
    1. read about negated character classes in perlre
    2. find a RE that matches a quoted string. A quoted string is a string that starts with a double quote, ends with a double quote and contains no double quote between those two.
    3. find a RE that matches a comma within a quoted string
    4. find out how to combine smaller REs into larger REs

Personally, I wouldn't approach many of these problems with regular expressions, as the time invested to craft such a special RE takes much too long for me, when a step-by-step solution is immediately available.

perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The $d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider ($c = $d->accept())->get_request(); $c->send_response( new #in the HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web

In reply to Re: Not find a word / remove first char in string / remove last value in list by Corion
in thread Not find a word / remove first char in string / remove last value in list by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.