Regular expressions, part 1: why you should care
A magic circle.This post is about regular expressions, what they do, and how they can help you.
It looked an extremely thorough job. Whoever had chalked it was clearly very aware that its purpose was to divide the universe into two bits, the inside and the outside.
— Eric, Terry Pratchett
Everyone loves strings. Most programs spend much of their time shunting them around. They're something that humans love and computers, generally, hate. I mean, they might not tell you to their face, but after hours, when you've all logged out and gone home, let me tell you, your computer is propping up a bar somewhere complaining about you and your human need for string handling.
Humans like strings because they're good for holding human language-- a field which computers, by and large, find opaque and puzzling. I'm not just talking about
- There is no reverse gear on a motorcycle; a friend of mine found this out quite suddenly the other day.
- Dduw, mae bywell yn mhen i.
- every book has an ISBN, ten digits long, of the form 1932857176 (though this will change soon)
- in the US, most people have a social security number of the form 078-05-1120.
Next part: how to write a regular expression.
0 comments:
Post a Comment