Regex Replacing
 
Replacing using regexes
  • Instead of m// , use s///
     
  • s/FSC/Follett Software Company/; would spell out FSC.
     
  • s/(Chuck|Charles) (E\. )?Follett/Tom Schenck/i; changes a number of variations on Chuck's name to Tom's. The /i makes it case-insensitive in the match.
Replacing with backreferences
  • The replacement part of a regex can contain references to the search part.
     
  • s/(\d\d)-(\d\d)-(\d\d\d\d)/$3$1$2/;
    changes dates in the form "mm-dd-yyyy" to "yyyymmdd" for sorting.
Index
Introduction
What Is Perl?
Perl Resources
Running a Perl Program
Perl Thinking
Data Types
Scalars
Strings: Single Quoted
Strings: Double Quoted
Scalar operations
Scalar comparisons
Variables
Lists
Using Lists
Control Structures
Hashes
Hash Manipulation
File Handling
Regex Matching
Regex Matching: Ex. 1
Regex Matching: Ex. 2
Regex Replacing
Subroutines
Anonymous subs
References
Structures
Modules
Modules: File::Find
Modules: Internet
Modules: Win32::*
Everything Else
  Next page >>>