Your leaking thatched hut during the restoration of a pre-Enlightenment state.

 

Hello, my name is Judas Gutenberg and this is my blaag (pronounced as you would the vomit noise "hyroop-bleuach").



links

decay & ruin
Biosphere II
Chernobyl
dead malls
Detroit
Irving housing

got that wrong
Paleofuture.com

appropriate tech
Arduino μcontrollers
Backwoods Home
Fractal antenna

fun social media stuff


Like asecular.com
(nobody does!)

Like my brownhouse:
   more about regular expressions than I had ever wanted to learn
Saturday, September 30 2017
I had what could possibly be characterized as the mildest of hangovers today, and though it eventually made me take a long nap in the late afternoon, it didn't take away much from my productivity. For the first time since her hospitalization, Gretchen joined me in Saturday morning coffee, which we enjoyed on the couch in the living room in front of another fire fueled by actual firewood.
Later I brought out my multimeter, a small notebook, and a jeweler's illuminated loupe so I could figure out some of the higher-voltage circuitry on the mostly non-functional Actiontec Q1000 DSL Router that is lying around in a disassembled state taking up room in the laboratory. I figured out a few things, including the polarity of three on-board surface-mount diodes and the nature of an eight-pin voltage regulator, though none of this helped me get the thing working in a useful way. So it ended up in my collection of electronic scrap.It had been raining this morning, but that soon let up and gave Gretchen the opportunity to walk the dogs, who stayed in the forest digging for chipmunks for hours afterwards.
At some point I made a number of fixes to some lingering bugs on my email editing system. I was so satisfied with that that I then turned my attention to a long-procrastinated task: getting this online journal to a point where it could be back online (it has been offline for months). I needed to implement some string functions to alter the text in a few places, though this altering was too complicated for the PHP function str_replace. I would need to use regular expression search patterns and a php function called preg_replace, which can search for those patterns and then replace either the whole found pattern or just parts of it. The replacing parts of it was the complicated thing that the documentation had trouble explaining, but late tonight I had the satisfaction of finally figuring it out. Here's the thing I learned, in example form:
A regular expression that looks like this: ~[^a-zA-Z]XX[^a-zA-Z]~ (and defined in PHP as $regBasis = '~[^a-zA-Z]XX[^a-zA-Z]~';) will look for and find any occurrence of the phrase XX that is preceded and followed by non-letter characters. Thus this expression will find XX or 1XX2 or .XX;. The thing I needed preg_replace to do was replace the XX with something else while leaving the single characters on either side of it the same. This meant I had to catch those characters for later production. In a regular expression, you do that by enclosing parts of the expression with parentheses. Then later, in the replacement phrase, those replacements are given by ordinal number, each proceeded by a dollar sign. The regular expression thus turns from ~[^a-zA-Z]XX[^a-zA-Z]~ to ~([^a-zA-Z])XX([^a-zA-Z])~ and the preg_replace looks like this: $result = preg_replace('~([^a-zA-Z])XX([^a-zA-Z])~', '$1NEW_TEXT$2', $in);. This is a lot more about regular expressions than I had ever wanted to learn, but now that I know it, I have a feeling it will prove useful.


For linking purposes this article's URL is:
http://asecular.com/blog.php?170930

feedback
previous | next