regular expressions

How to search for multiple regex patterns in many files with `ffx`

I recently created a command I named ffx that lets you search your filesystem for files that contain multiple strings or regular expressions. This post describes and demonstrates its capabilities. (There’s a little video down below if you want to see how it works before reading about it.)

My Scala Sed project: More features, returning strings

Table of Contents1 - Basic use2 - Using a Map3 - Match expressions4 - Sed limitations5 - My Sed project6 - Bonus: Factories and HOFs

My Scala Sed project is still a work in progress, but I made some progress on a new version this week. My initial need this week was to have Sed return a String rather than printing directly to STDOUT. This change gave me more ability to post-process a file. After that I realized it would really be useful if the custom function I pass to Sed had two more pieces of information available to it:

  • The line number of the string Sed passed to it
  • A Map of key/value pairs the helper function could use while processing the file

Note: In this article “Sed” refers to my project, and “sed” refers to the Unix command-line utility.

Back to top

Basic use

In a “basic use” scenario, this is how I use the new version of Sed in a Scala shell script to change the “layout:” lines in 55 Markdown files whose names are in the files-to-process.txt file:

Scala: How to use regex pattern matching in a match expression alvin February 17, 2019 - 12:58pm

Scala FAQ: How can I use regular expression (regex) pattern matching in a match expression (a Scala match/case expression)?

As I wrote in my Scala sed class post earlier today, Jon Pretty’s Kaleidoscope project lets you use string pattern-matching code in Scala match expressions. This enables regex pattern-matching code like this:

A little Scala `sed` class

A few times during the past year I got tired of trying to remember the Unix/Linux sed syntax while wanting to make edits to many files, so this weekend I wrote a little sed-like Scala class.

Regular expression examples (common regex patterns)

Regular expression FAQ: Do you have a list of common regular expression examples, i.e., the most common regex patterns used in programming languages like Java, Perl, PHP, Ruby, and others?

I've been asked several times, so I thought it might be helpful to post some of the most common regular expression examples that are used in programming. Honestly I haven't tested any of these yet -- I did them off the top of my head -- but I think they will work for most open source programming languages.

A Java regular expression example (featuring Pattern and Matcher classes)

Summary: Java regular expressions in Java 1.4, featuring regex expressions and pattern matching, using the new Java Pattern and Matcher classes.

The following Java example offers an introduction to regular expressions in Java 1.4. In this code we're creating a regular expression that can search for a date. Specifically, that date must be in a format of two digits, followed by a hyphen, followed by two digits, followed by a hyphen, followed by four digits.

This date pattern is created in this line of code:

Java regex examples - common regular expressions

Java FAQ: Can you share some examples of common Java regular expressions?

The following list shows some of the most common regular expressions that are used in computer programming. I haven’t tested any of these yet with Java, but I think most will work off the shelf, or should at least work with minor tweaks.

An interesting note is that there are several ways to write the same regular expression, and I intentionally tried to stress that in the examples below.

Mon, Jul 28, 2003

Here are a couple of new tips I've written on using regular expressions in Java 1.4. Both tips include complete, working source code examples.