Let's look over that regex first.
s/(\.[\W]+)([\w])/\1\u\2/ig;
The [\W]+ seems akward. If you mean for this to be spaces, why not say spaces, i.e., \s. Also, the brackets to signify a character class are unneccessary here. Also, when constructing a regex, you main goal is to match *only* what you want. What you want in this case is what comes after a period, but here you match that period also. Why not use a zero-width look-behind assertion? (aslo, it seems that you should check for more punctuation than a period). You don't need the char. class brackets on the \w either. Next, the \1 and \2 are a mistake; this is not part of the regex, per se, but rather the substitution, and thus you should say $1 and $2. Also, the /i is useless; i.e., \w's char. class includes both upper- and lower-case letters.

To capitilize at the beginning of a paragraph, you need to define what a paragraph is. Is it a tab indention? A certain number of spaces? Or is it just preceded by a blank line or two? Once you have that completed, you can then construe a regex to capitilize what you desire. To match a tab you can use \t; or \s to match all types of spaces. To match a paragraph that starts with a blank line or two, why not just put your read in perl's 'paragraph' mode. Then you can capitilize whatever appears first that's letters.

As for a hard return. . . what exactly do you mean by a hard return?

Update: Well, for a carraige-return a \r will do; for a newline a \n will do. I would offer a regex to show, but in the other post, now that I look at it, there are some fine ones already shown.


In reply to Re: Capitalizing letters? by dimmesdale
in thread Capitalizing letters? by KStowe

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.