Shortcuts for Character Ranges in Perl

Part of the Perl For Dummies Cheat Sheet

You're programming along in Perl and want to use a code shortcut to represent anything from a number to a non-number to any letter or number. You're in luck, because the following table gives you the code, shows you what it’s a shortcut for, and describes it.

Code Replaces Description
\d [0..9] Any digit
\w [a-zA-Z_0-9] Any alphanumeric character
\s [ tnrf] A whitespace character
\D ^[0..9] Any non-digit
\W ^[a-zA-Z_0-9] Any non-alphanumeric character
\S ^[ tnrf] A non-whitespace character
  • Add a Comment
  • Print
  • Share
blog comments powered by Disqus

SERIES
Perl For Dummies Cheat Sheet

Advertisement

Inside Dummies.com

Dummies.com Sweepstakes

Win $500. Easy.