On Tue, 24 Aug 2004, Errin Larsen wrote:

Perhaps:

   $scalar =~ s/^(a|an|the)\s*\b//i;

would work better.

<<SNIP>>

Is this capturing into $1 the a|an|the (yes) and the rest of the title into $2 (no?).

There is only one pair of parentheses, so only $1 is captured.

I still think it's prudent to capture everything else as $2, and then substitute such that the article captured in $1 is now the suffix:

    $scalar =~ s/^(a|an|the)\s*\b(.*)/$2, $1/i;

Which turns "A Hard Day's Night" into "Hard Day's Night, A". If you ever need the original string back -- the person who started this thread was trying to get this info into a MySQL database in such a way that it would sort by the first significant word and not the article that precedes it -- then you can reverse the change with something like:

   $scalar =~ s/(.*), \b(a|an|the)$/$2 $1/i;

and "Hard Day's Night, A" should once again be "A Hard Day's Night".

After doing so, will it reverse the two ( i.e. s/^(a|an|the)\s+(.*)\b/$2, $1/i )?

Your version should; the one above won't.

Also, what is the "\b"?

Word boundary.

it seems that the trailing "i" is for ignoring case; is that correct?

Yes.

Just need some help with RE!!

`perldoc perlre`

Or the wonderful -- really! -- book, _Mastering Regular Expressions_.



--
Chris Devers      [EMAIL PROTECTED]
http://devers.homeip.net:8080/blog/

np: 'Colt 45'
     by
     from 'Television Theme Songs'

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to