web blazonry web development scripts and tutorials
 
Web blazonry.com
   Home       PHP       Name Generators       Perl       CSS       Javascript       Java       devTips       Resources   

Perl Home

Perl Scripts
  Count Links
  Mail to MySQL
  ProcLog Files
  Search and Replace
  Site Monitor
  UnTabify

Perl Articles
  csv2htm Converter
  OLE Automation
  Regular Expressions
  SubDir Recursion

Perl Resources
  Regular Expressions Quick Reference
  Regular Expressions Examples
  Recommended Sites
  Bestselling Perl Books
  Free Perl Books (new)
  Free Python Books(new)





Perl: Examples of Regular Expressions

# convert to UPPERCASE
# returns $line = $line (all in uppercase)

$line =~ tr/a-z/A-Z/;


# convert to lowercase
# returns $line = $line (all in lowercase)

$line =~ tr/A-Z/a-z/;


# remove leading whitespace
# returns $line with no leading whitespace

$line =~ s/^\s+//;


# remove trailing whitespace
# returns $line with no trailing whitespace
# note: this will also remove \n

$line =~ s/\s+$//


# check for Y2K date (4-digit year specified)
# format exactly: nn/nn/nnnn or nn-nn-nnnn
# returns true if proper format

($line1 =~ m/[0-9]{2}[\/|-][0-9]{2}[\/|-][0-9]{4}/)


# find word that is bolded
# returns: $1 = 'text'

$line = "This is some <b>text</b> with HTML <tags> and ";
$line =~ m/<b>(.*)<\/b>/i;


# convert <STRONG> to <B>
$line =~ s/<(\/?)strong>/<$1b>/gi;


# strip HTML tags (not the best way)
# returns $line = 'This is some with HTML and words'

$line = "This is some <b>text</b> with HTML <tags> and words";
$line =~ s/<(.*?)>//gi;


See also for more about regular expressions:



 

Newest Pages
Test Google Ads Part 2
Free Linux Admin Books
Free Linux Books for Programmers
Free Books for Linux on the Desktop
Free PHP Books
Free JavaScript Books
Free Java Books - Advanced
Free Java Books - Basic
Free Perl Books
Free Python Books
Quote of the Day (PHP)
Debugging Part 2
How to Test Google Ads
Most Popular Pages
U.S. Name Generator
Baby Name Generator
Wu Name Generator
Popup Windows (JavaScript)
Intro to Web Databases (PHP, MySQL)
Upload and Resize an Image (PHP)
How To Install Apache + PHP + MySQL

Least Popular Pages
iNews Aplet (Java)
Java Resources)
Site Monitor (Perl)
Load Order of Images(Javascript)
 
 

  © 1997-2008. astonishinc.com   All Rights Reserved.