Skip to navigation

Archive for the 'Regular expressions' Category

Test your regular expressions online

Wednesday, June 17th, 2009

Speaking of regular expressions, I found out you can test them online at regexpal.com. Neat.

Emacs regular expressions: match at least n occurrences of character class

Tuesday, June 16th, 2009

Aside: I just discovered the very useful Emacs regex builder tool. Type M-x regexp-builder.
I wanted a regular expression to match the pattern of mutt mail edit buffers, to apply mail-mode, but I did not want to match the muttrc and mutt.hooks files I have.
Mail edit buffers get a pattern that starts with “mutt”, followed by [...]

Filename pattern matching via bash extended globbing and find regular expressions in shell scripts

Tuesday, January 20th, 2009

I was confused that bash would expand some patterns nicely to match filenames when I was on the commandline, but the same pattern would not work from inside a shell script. For example, the following pattern would nicely match all files in the current directory not having an “Rnw” or “tex” extension on the commandline:
ls [...]

Sed example 2

Monday, June 25th, 2007

Replacing whitespace, lifted directly from the handy collection of sed one-liners at Sourceforge:
Delete all leading whitespace from line (tabs and spaces):
sed ’s/^[ \t]*//’
Delete whitespace at end of line:
sed ’s/[ \t]*$//’
Delete leading and trailing whitespace:
sed ’s/^[ \t]*//;s/[ \t]*$//’

Sed example 1

Tuesday, May 1st, 2007

Many things are easiest to learn by looking at examples. I find this to be especially true for sed. Sed stands for “stream editor”, and it is very handy to perform bulk editing of text files. To get started, I refer you to this very nice tutorial. I’m planning to archive some of the small [...]