Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Here is my vision. Please entertain it, if you would. If you haven't been able to tell, I'm serious, and I'm a regex fanatic. Learning Perl's Regular Expressions
  • Familiarize the reader with the tasks that regular expressions are intended to complete.
    • What is a regular expression (regex)?
    • What can they do?
    • What are some practical uses for them?
    • What are some impractical uses for them?
    • How can they solve daily programming problems?
  • Abstract thinking about regexes.
    • How to explain a regex's purpose.
    • How to tackle a given parsing problem with a regex.
    • How to say what you mean, and mean what you say.
    • What else is out there, apart from regexes.
  • Simple patterns.
    • Plain text: /hello world/
    • Safe patterns: /hello \Q$place\E/
    • Character classes: /[Hh]ello [Ww]orld/
    • Case-insensitivity: /hello world/i
    • Alternation: /hello|goodbye/
    • Matching something other than $_: $foo =~ /hello/
  • More "patterny" patterns.
    • Dot: /h.ll/
    • Quantifiers: /hello(?: +world)?/
    • Macros: /hello\s+world/
    • Anchors: /^hello,?\s+world$/
    • Alternate m// characters: m!a/b/c!
  • Getting something back.
    • Capturing: /hello,?\s+(\w+)/
    • Back-references: /\b(\w)\w+(\1)\b/
    • Global matching: /(\d+)/g
    • Regex-y functions: split(), grep(), map()
    • Useful variables: $1, @-, @+
    • Not-so-useful variables: $`, $&, $'
  • More modifiers.
    • Modifying .: /a.b/s
    • Modifying ^ and $: /^foo$/m
    • Explaining your regex using /x
    • Using qr// and /o
  • Breakpoint: greediness and backtracking
    • What is backtracking, and how does it work?
    • What is greediness, and how do you avoid it?
    • Minimal (lazy) vs. maximal (greedy): /a\w+?z/
    • Understanding the "left-most longest" rule.
  • Substitution.
    • Using s///.
    • Calling functions with /e.
  • Simple assertions.
    • Positive look-ahead: /foo(?=bar)/
    • Negative look-ahead: /foo(?!bar)/
    • Common traps: "aaabar" =~ /a+(?!bar)/
  • More assertions.
    • Positive look-behind: /(?<=foo)bar/
    • Negative look-behind: /(?<!foo)bar/
    • The constant-width assertion plague: /(?<=ab+a)/
    • The cut assertion: /(?>a+)a/
  • Logic-flow in regexes.
    • The conditional assertion: /(?(...)a|b)/
  • Embedding code.
    • Advanced use of the /e modifier.
    • The evaluate assertion: /(?{ code })/
    • The delayed regex assertion: /(??{ regex })/
  • Advanced global searching.
    • The pos() function
    • The \G anchor and the /gc modifiers.
  • Common mistakes.
    • $&, et. al.
    • Problems with /$foo/.
    • Matching too much.
    • Wasteful modifiers.
  • Optimizing your regexes.
    • "Death to .*."
    • Match only what you want.
    • Unrolling the loop.
  • Concrete applications of regexes.
    • Data transformation for sorting.
    • Matching in reverse ("sexeger").
  • Regex tools and resources.
Please give me your input. Is this too much for a tutorial? I want it to be in the form of Learning Perl, with exercises and such, but I want it to include as much as it should so that one has a firm grasp on Perl's regexes.

japhy -- Perl and Regex Hacker

In reply to Learning Perl's Regular Expressions by japhy
in thread japhy and mystery by japhy

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (1)
As of 2022-10-01 14:59 GMT
Find Nodes?
    Voting Booth?
    My preferred way to holiday/vacation is:

    Results (0 votes). Check out past polls.