6. Pattern Matching


Copying and Substituting Simultaneously


// by Scott McCoy [tag at cpan.org] 

 /* Copying and Substituting Simultaniously */
dst = Regexp("this")->replace(src, "that");
 /* Copying and replacing...Same thing */
dst = Regexp("this")->replace(src, "that");
 /* Strip to basename */
 // Note this is best done with string manipulation functions, regexp here is

 // wasteful.  Same is true in perl.

dst = Regexp("^.*/")->replace(argv[0], "");

string capword = Regexp("[a-z]+")->replace
            lambda (string c) { 
                c[0] = upper_case(c[0]); 
                return c; 
            } );

/* For the captured substitution, I'll have to figure out PCRE. */

Matching Letters

Matching Words

Commenting Regular Expressions

Finding the Nth Occurrence of a Match

Matching Multiple Lines

Reading Records with a Pattern Separator

Extracting a Range of Lines

Matching Shell Globs as Regular Expressions

Speeding Up Interpolated Matches

Testing for a Valid Pattern

Honoring Locale Settings in Regular Expressions

Approximate Matching

Matching from Where the Last Pattern Left Off

Greedy and Non-Greedy Matches

Detecting Duplicate Words

Expressing AND, OR, and NOT in a Single Pattern

Matching Multiple-Byte Characters

Matching a Valid Mail Address

Matching Abbreviations

Program: urlify

Program: tcgrep

Regular Expression Grabbag