web blazonry web development scripts and tutorials Get best price on Unlocked Samsung Galaxy A21
   PHP       Name Generators       Perl       CSS       Javascript       Java       MySql       How Tos       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)

Bookmark and Share




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 Ver. 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
Baby Name Generator
U.S. Name Generator
Wu Name Generator
Popup Windows (JavaScript)
Upload and Resize an Image (PHP)
How To Install Apache + PHP + MySQL
Intro to Web Databases (PHP, MySQL)

Least Popular Pages
iNews Applet (Java)
Java Resources
Site Monitor (Perl)
PHP Resources
 
 

  privacy policy     ||     © 1997-2016. astonishinc.com   All Rights Reserved.