Skip to Content
Perl One-Liners
book

Perl One-Liners

by Peteris Krumins
December 2013
Intermediate to advanced
168 pages
2h 49m
English
No Starch Press
Content preview from Perl One-Liners

Chapter 8. Useful Regular Expressions

In this chapter, we’ll look at various regular expressions and how to use them in some handy one-liners. The regular expressions include matching IP addresses, HTTP headers, and email addresses; matching numbers and number ranges; and extracting and changing matches. I’ll also share some regular expression puzzles and best practices. This chapter will be a bit different from previous ones because I’ll start with a regular expression and then write a one-liner that uses it.

8.1 Match something that looks like an IP address

/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/

This regular expression doesn’t actually guarantee that the thing that matched is, in fact, a valid IP; it simply matches something that looks like an ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Perl Best Practices

Perl Best Practices

Damian Conway
Perl Cookbook

Perl Cookbook

Tom Christiansen, Nathan Torkington
Minimal Perl

Minimal Perl

Tim Maher
Learning Perl, 7th Edition

Learning Perl, 7th Edition

Randal L. Schwartz, brian d foy, Tom Phoenix

Publisher Resources

ISBN: 9781457185281Errata