Blog Archives

Can regular expressions parse HTML or not?

Can regular expressions parse HTML? There are several answers to that question, both theoretical and practical. First, let’s look at theoretical answers. When programmers first learn about regular expressions, they often try to use them on HTML. Then someone wise

Tagged with: ,
Posted in Software development

Learn one Perl command

A while back I wrote a post Learn one sed command. In a nutshell, I said it’s worth learning sed just do commands of the form sed s/foo/bar/ to replace “foo” with “bar.” Dan Haskin and Will Fitzgerald suggested in

Tagged with: , ,
Posted in Software development

Just what do you mean by "number"?

Tom Christiansen gave an awesome answer to the question of how to match a number with a regular expression. He begins by clarifying what the reader means by “number”, then gives answers for each. Is −0 a number? How do

Tagged with:
Posted in Uncategorized

Roman numeral puzzle

I noticed an ad for Super Bowl XLVI on a pizza box this morning. The Roman numeral XLVI does not repeat any character. This brought up a couple questions. How many Roman numerals are possible if you’re not allowed to

Tagged with: ,
Posted in Math

Learn one sed command

You may have seen sed programs even if you didn’t know that’s what they were. In online discussions it’s common to hear someone say s/foo/bar/ as a shorthand to mean “replace foo with bar.” The line s/foo/bar/ is a complete

Tagged with: , ,
Posted in Software development

Efficiency of regular expressions

I’ve never optimized a regular expression.  I typically use regular expressions in scripts where efficiency doesn’t matter. And sometimes I do some regular expression processing as part of a larger program in which the bottleneck is somewhere else. But I’ve

Tagged with:
Posted in Software development

Good old regular expressions

Here are two examples that persuaded me long ago that regular expressions could be powerful. Both come from The Unix Programming Environment by Kernighan and Pike (1984). The first problem is to produce a list of all English words that

Tagged with:
Posted in Computing, Software development

Daily tip Twitter account FAQ

This post answers some frequently asked questions regarding my daily tip accounts on Twitter. How many followers do you have? About 2800 people are following at least one of these accounts at the time of writing, each following between 2

Tagged with: , , ,
Posted in Uncategorized

Twitter daily tip news

I have five Twitter accounts that send out one tip per day, including a new one I just added last week. Regular expressions @RegexTip started over today. It’s a cycle of tips for learning regular expressions. It sticks to the

Tagged with: , , ,
Posted in Python

Regular expressions in R

Notes on using regular expressions in R. R uses POSIX regular expression syntax by default but you can ask it to use Perl’s flavor of regular expressions. Related links: Regular expressions in C++, Mathematica, Python, R, PowerShell R for programmers

Tagged with: ,
Posted in Uncategorized

Regular expressions in Mathematica

Regular expressions are fairly portable. There are two main flavors of regular expressions — POSIX and Perl — and more languages these days use the Perl flavor. There are some minor differences in what it means to be “like Perl”

Tagged with: ,
Posted in Uncategorized

New daily tip feeds: RegexTip and ProbFact

A few weeks ago I started a Twitter account @SansMouse with daily tips on Windows keyboard shortcuts. That’s gone well, so I decided start two more daily tip accounts: @RegexTip and @ProbFact. If you don’t use Twitter, you can follow

Tagged with: ,
Posted in Uncategorized

Table-driven text munging in PowerShell

In my previous post, I mentioned formatting C++ code as HTML by doing some regular expression substitutions. I often need to write something that carries out a list of pattern substitutions, so I decided to rewrite the previous script to

Tagged with: ,
Posted in PowerShell

API symmetry

Symmetric APIs are easier to use. I was reminded of this when doing some regular expression programming in Python and comparing it to Perl. Perl’s regular expression operators for search and replace are symmetric in a way that their Python

Tagged with: , , ,
Posted in Python, Software development

Regular expressions in PowerShell and Perl

This is one of the most popular pages on my web site: Regular expressions in PowerShell and Perl It’s about how you use regular expressions in PowerShell — how to do matches, replacements, etc. — rather than the grammar of

Tagged with: ,
Posted in PowerShell