Regularer Expressions

surprisetalk2 pts0 comments

furialog

furia<br>furialog &middot;<br>Every Noise at Once &middot;<br>New Particles &middot;<br>The War Against Silence &middot;<br>Aedliga (songs) &middot;<br>photography &middot;<br>other things &middot;<br>contact

furialog

Latest

&middot; Regularer expressions

&darr;previous 10

email

RSS feeds

(in any entry)<br>child<br>essay<br>fiction<br>listen<br>pets<br>photo<br>poem<br>tech

&para; Regularer expressions &middot; 9 July 2026 tech

Javascript, like most modern programming languages, allows you to use regular expressions to parse values out of formatted strings. Here, for example, is a fairly nice regexp template to get the interesting stuff out of an Apache web-log line.

/^(?.+?) - - \[(?..)\/(?...)\/(?....):(?.+?) -0400\] "(?.+?) (?.+?) (?.+?)" (?.+?) (?.+?) "(?.*?)" "(?.+?)"$/

Regexps can get very ugly, but this one mostly hasn't, although you have to be careful to sprinkle exactly the right number of backslashes on it.

Javascript also has a fairly nice way to use a template to make formatted strings out of individual properties.

`${ipaddress} - - [${day}/${month}/${year}:${time} -0400] "${request} ${url} ${protocol}" ${status} ${size} "${referrer}" "${useragent}"`

But we should aspire to fill our lives with things that are more than just fairly nice. I dislike fastidious bureacracy, and I dislike it even more when it multiplies spuriously. You can do regexp extraction in DACTAL, too, if you want. But it also has a ruthlessly streamlined template function of its own, designed specifically for the purpose of dealing with the most common forms of pattern-formatted text. And because you're just as likely to want to construct pattern-formatted text as you are to want to slice it apart, DACTAL templates can be used in both directions.

parse<br>[~~ipaddress - - [day/month/year:time -0400]] "request url protocol" status size "referrer" "useragent"]

format<br>[~ipaddress - - [day/month/year:time -0400]] "request url protocol" status size "referrer" "useragent"]

The only caveat is that this particular example needs brackets inside the template, and since DACTAL uses brackets to enclose the whole literal, you have to double the inner closing bracket after "-0400" in both directions. But otherwise I think this is almost literally as anti-bureaucratically minimal as an extraction/construction scheme could possibly be.

Site contents published by glenn mcdonald under a Creative Commons BY/NC/ND License except where otherwise noted.

middot expressions formatted template regularer furialog

Related Articles