Capitalize all sentences : substitution « Regular Expression « Perl

Home
Perl
1.Array
2.CGI
3.Class
4.Data Type
5.Database
6.File
7.GUI
8.Hash
9.Language Basics
10.Network
11.Regular Expression
12.Report
13.Statement
14.String
15.Subroutine
16.System Functions
17.Win32
18.XML
Perl » Regular Expression » substitution 
Capitalize all sentences
    

#!usr/bin/perl

use strict;
use warnings;

my $string1 = "lets see. This is a test";

capitalize$string1 );

sub capitalize
{
   my $string = shift();
   print "$string\n";
   $string =~ s/(([.!?]|\A)\s*)([a-z])/$1\u$3/g;
   print "$string\n";
}

   
    
    
    
  
Related examples in the same category
1.Options for the substitution operator.
2.Replace pattern
3.Replace pattern with ()
4.Substitute I with N and print
5.Substitute N with J
6.Substitute every T with M
7.Substitute first T with an M
8.Substitute first occurrence of "blue" with "red"
9.Substitute tom with Mary
10.Substitution Example
11.Substitution Modifiers
12.Using substitutions to clean up input data.
13.Using Patterns with Substitutions
14.Changing substitution delimiters
15.Increase salary with pattern match
16.Evaluate replacement
17.Alternation: /John|Karen|Steve/ will match a line containing John or Karen or Steve.
18.Options for the S Operator
19.Ignore case, global substitution
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.