Let us chat about nothing.

Now over here, if you’ll follow me, we have something rather special.

Read this first

Learn Regex the Easy Way, Part 6: Alternation and Grouping

Quick Recap

In Part 5, we covered metacharacters, escaping with backslash, and the dot wildcard. We learned the 14 special characters and how to match them literally. Now let’s combine patterns with “or” logic and control what our quantifiers apply to.

The Pipe Means OR

The pipe character | means “or” in regex. cat|dog matches either “cat” or “dog.”

Grouping with Parentheses

Here’s where it gets critical. Without parentheses, the pipe applies to everything on each side:

cat|dog food     Matches "cat" OR "dog food"
                 NOT "cat food" or "dog food"

With parentheses, you limit the scope:

(cat|dog)        Either "cat" or "dog"
[[:blank:]]      A space
food             Literal "food"

Compact: (cat|dog) food

MATCH THESE

  • cat food
  • dog food

DO NOT MATCH THESE

  • bird food
  • cat
  • dog
  • food

Multiple Alternatives

You can have as many alternatives as you need: (red|green|b...

Continue reading →


Learn Regex the Easy Way, Part 5: The Dot, Escaping, and Special Characters

Quick Recap

In Part 4, we covered quantifiers: * (zero or more), + (one or more), ? (optional), and {n,m} (specific counts). We also learned that quantifiers apply to the element directly before them. Now let’s talk about the characters regex treats as special and how to handle them.

The 14 Metacharacters

Regex has 14 characters that have special meaning. These are called metacharacters:

.  *  +  ?  ^  $  {  }  [  ]  (  )  |  \

When the engine sees any of these, it doesn’t treat them as literal characters. It interprets them as instructions. We’ve already used several: ^ and $ as anchors, * + ? as quantifiers, [] for character classes.

One note: This lesson isn’t about what these special characters do. A future lesson will cover what meta characters are used for in more detail.

Escaping with Backslash

What if you actually want to match a literal dot, or a literal asterisk? You...

Continue reading →


Learn Regex the Easy Way, Part 4: Quantifiers

Quick Recap

In Part 3, we covered character classes: square brackets that match one character from a set, POSIX classes like [[:digit:]], and negation with [^...]. Now let’s talk about how many characters to match.

The Four Core Quantifiers

A quantifier tells the regex engine “how many of the previous thing do I want?” There are four you’ll use constantly:

Quantifier Meaning Example * Zero or more ab*c matches ac, abc, abbc + One or more ab+c matches abc, abbc, but NOT ac ? Zero or one (optional) colou?r matches color and colour {n} Exactly n a{3} matches aaa

A Critical Detail: What Gets Quantified

The quantifier applies to the thing directly before it. This is probably the most common beginner mistake.

abc+         Matches: ab followed by one or more c's
             (abcc, abccc, etc.)
             Does NOT mean "one or more abc"

If you want “one or more abc,”...

Continue reading →


Learn Regex the Easy Way, Part 3: Character Classes

Learn Regex the Easy Way, Part 3: Character Classes

Quick Recap

In Part 2, we learned about anchors and boundaries. The caret ^ matches the start of a line, $ matches the end, and \b matches word edges. They match positions, not characters. Now let’s match actual characters, but with more control than just typing them out literally.

Square Brackets Create a Character Class

A character class is a set of characters inside square brackets: [abc]. It matches any ONE character from that set. Not all of them. Not some of them. Exactly one character from the options inside the brackets.

[abc]    Match a single character: a, b, or c

MATCH THESE

  • a
  • b
  • c

DO NOT MATCH THESE

  • d
  • e
  • ab
  • abc

Notice that [abc] does NOT match “ab” or “abc.” It matches exactly one character. If your text contains “ab,” the regex will match just the “a” (the first character from the set it finds).

Ranges

You...

Continue reading →


Learn Regex the Easy Way, Part 2: Anchors and Boundaries

Learn Regex the Easy Way, Part 2: Anchors and Boundaries

Quick Recap

In Part 1, we talked about what regular expressions are, why they look intimidating (they really do look like a cat sat on your keyboard), and why verbose mode with comments is the way to learn them. We also set up regex101.com in PCRE2 mode. Now let’s write some actual regex.

Anchors Match Positions, Not Characters

Here’s the first counterintuitive thing about regex: not everything matches a character. Some symbols match a position in the text. These are called anchors.

Think of it this way. When you type the letter a in a regex, the engine finds the letter “a” in your text and consumes it. The match moves forward one character. Anchors don’t do that. They check “am I at a certain position?” and if yes, the match continues, but the engine doesn’t move forward. Nothing is consumed. No character is matched. Just a...

Continue reading →


Make Regular Expressions the Easy Way

Introduction and The Problem

Regular Expressions have been around for a long time and can solve problems nothing else really seems to be able to. There are a lot of great examples of where to use them, and where to not use them. Every once in a while, a new product (or version of a product) comes out which includes regex support. Some people get excited about being able to use regular expressions. They tell other people about it.

Then they realize most people seem to think Regular Expresions, or regex for short, are the hardest problem in coding.

There are a group of people who get nervous about regex, or really just do not want to work with any regular expressions. I do not blame them; it looks weird.

However, if I can become proficient at regex, so can you. The following is a set of regular expressions I created, some in part due to what I am recommending in this post.

My ...

Continue reading →


Growl in Retirement

Growl is being retired after surviving for 17 years. With the announcement of Apple’s new hardware platform, a general shift of developers to Apple’s notification system, and a lack of obvious ways to improve Growl beyond what it is and has been, we’re announcing the retirement of Growl as of today.

It’s been a long time coming. Growl is the project I worked on for the longest period of my open source career. However at WWDC in 2012 everyone on the team saw the writing on the wall. This was my only WWDC. This is the WWDC where Notification Center was announced. Ironically Growl was called Global Notifications Center, before I renamed it to Growl because I thought the name was too geeky. There’s even a sourceforge project for Global Notifications Center still out there if you want to go find it.

We’ve had a lot of support over the years; from our hosting providers at Network Redux...

Continue reading →


The responsibility of ad networks

Ad networks are serving up malware. This is a practice known as malvertising. This scenario is becoming more and more common as an infection vector utilizing different exploit kits.

Imagine this. You browse a website. Then you get an infection. The website is one which is well known, in the top 500 websites on the internet, and has been around for years. This website provides you with daily news and traffic reports, weather, you name it. You get an infection from a source you trust and you do not even know it.

Antivirus is ineffective. You now have to deal with it on your own. You may even have to pay a ransom in some cases unless you back up your files.

THIS IS INSANE

You should not have to worry about using the internet on legitimate websites. Advertising networks and those who serve ads on their websites complain about adblocking, however when the only way to prevent an infection...

Continue reading →


SSL, TLS, PCI and your app

TLS superseded SSL a very long time ago. However SSL never really went away since it was still considered to be safe. That changed last year and this year. It is no longer safe to use and needs to be removed, else face the consequences. Going one step further, TLS 1.0 is also a bad idea. Utilizing TLS 1.2 is really the best option.

If you are writing an application and utilizing encryption from the operating system, then that should most likely take care of what needs to be done in the application itself. You will likely have to configure the host or web server, but that is outside of your app.

However, if you are writing an application and specifically bundling SSL and/or TLS, the time has come to think about and change what you are doing. The ramifications here are that if you sell your product to a customer who processes credit cards and they get dinged, your application will...

Continue reading →


Family Sharing is here, you must enable it developer. Or you are a jerk.

One thing that i do not see a lot of people talking about this week is the new Family Sharing that was introduced at WWDC. At first it seems like a neat way to just share some pictures and photos, locations and some content. However it is critical that you, the developer, pay attention to this.

YOU MUST ENABLE FAMILY SHARING

I cannot stress this enough. It’s an optional thing that you have to actually enable in itunesconnect, but in reality if you do not enable family sharing then you sir or madam are a grade a, section 7, 9th level of hell jerkface. Or at least that’s how you will appear to your customers. The reason is simple, this makes it easier to share content with your family. If you hate families do not enable this option.

i.e. you’re going to enable this. Go do it now, I’ll wait. When you get back I’ll explain my reasoning here.

Apple built this with the idea of making life...

Continue reading →