How to Learn and Use Regular Expressions (Regex)

Whoever would have thought that something that looks like gibberish would actually have such powerful usages. Look at this example:

\d\d[/]\d\d[/]\d\d[ ][-][ ]

Would you believe that it’s actually an expression that matches anything of the format of “12/06/08”? Amazing.

I’ve been putting off learning about regular expressions (regex) for the longest time because it seems overly complicated — but I was forced to learn more about it after a recent application demanded of it. And boy was I glad to have finally jumped into it — it’s simply one of the best ways to search for any text pattern.

With regular expressions, you can search for any number of characters, specify whether it’s a number or letter, and even specify a range, like only accept alphabets between B and E. Or only numbers from 1-5.

So if you think about it, the sample regular expression string up there can actually be improved upon. For instance, since the date format is dd/mm/yy, we know that dd can go higher than 31, nor can it go lower than 1. And similarly, we know that for mm, it’s between 01 to 12. The tricky part is yy, because it can vary, depending on how you’re going to use this date. If your application’s more geared towards the future, then keeping the first digit to 0 or 1, and the 2nd digit from 0 to 9 should be just fine.

So as you can see, if you’re a developer, then regular expressions (regex) should be something that you are very familiar and comfortable with, because it makes your life so much easier!

​Read More

Tim Ferris 4 Hour Work Week Book Review

When I first heard this joke some time ago, I thought it was just like any other joke. But I saw it again recently (in Tim Ferris’ book, The 4-Hour Workweek), it suddenly dawned upon me about how strong the underlying message is.

An American investment banker was at the pier of a small coastal Mexican village when a small boat with just one fisherman docked. Inside the small boat were several large yellow-finned tuna. The banker complimented the Mexican on the quality of his fish and asked how long it took to catch them.

The Mexican replied, “Only a little while.”

The banker then asked why he didn’t stay out longer and catch more fish. The Mexican said he had enough to support his family’s immediate needs.

The banker was puzzled and then asked, “But what do you do with the rest of your time?”

The Mexican fisherman said, “I sleep late, swim a little, play with my children, take a siesta with my wife Maria, stroll into the village each evening where I sip wine and play guitar with my amigos. I have a full and busy life, Senor.”

The banker scoffed, “I am a Harvard MBA and could help you. You should spend more time fishing and with the proceeds buy a bigger boat. With the proceeds from the bigger boat you could buy several boats. Eventually you’ll have a fleet of fishing boats. Instead of selling your catch to a middle man, you would sell directly to the processor, eventually opening your own cannery. You would control the product, processing and distribution. You would need to leave this small coastal fishing village and move to Mexico City, then Los Angeles, and eventually to New York City where you will run your expanding enterprise.”

The Mexican fisherman asked, “But, Senor, how long will this all take?”

To which the banker replied, “Five to ten years.”

“But what then, Senor?”

The banker laughed and said, “That’s the best part. When the time is right, you would announce an IPO and sell your company’s stock to the public and become very rich. You would be worth millions!”

“Millions, Senor? Then what?”

The banker said, “Then you would retire, move to a small coastal fishing village, take siesta with your wife, play with your kids, stroll to the village in the evenings where you would sip wine and play your guitar with your amigos.”

Yes, then, after wasting your years in the pursuit of money you might finally realize those very dreams that could have been yours without it!

It makes you think about what you really want out of life:

  • Working to get a fast car? And then what?
  • Working so that you can get a relaxing retirement? When you’re in your final years and barely able to enjoy yourself?

Perhaps the point is — why are you working your ass off for? Would you choose money or something that gives you real meaning to your life? Maybe we’re missing the point of life. The 4-Hour Workweek gave me a tonne of insight. If anything, it made me remember about my goals, and made me realise how much I was getting “lost”, as though conformity was a requirement for success. And that “success” was something defined by the people around you, and not yourself. It’s a thoroughly good read that’s entertaining at the same time. It’s been a while since I had a book that I couldn’t put down like this.

In summary, I think that the irony of life is that we give up health and the best years of our life in our youth for the sake of wealth, just for what? To try to recapture our health in our old age with our wealth? Don’t get me wrong — have adequate cash flow is important, but you should be considering a good work-life balance to get the most out of your life. If you’re saving up for retirement and not experiencing life to the fullest in your youth — have you asked yourself why?

I think it’s really important to have a sense of purpose and truly know what you’re living life for. Reading Tim’s book only refreshed, reinforced, and reminded me what I’m really working for.

​Read More

Leitner Flashcard Learning System

In the early 70’s a German psychologist named Sebastian Leitner devised a learning system that makes selective learning possible with less effort than the traditional method of studying a set of flashcards sequentially.

Leitner’s system consists of a cardboard box separated into a number of compartments. The compartments are filled with flashcards and the flashcards are moved from one compartment to another, according to the current level of knowledge. When a flashcard is answered correctly it is promoted to the next compartment. When a flashcard is answered incorrectly it is demoted to the first compartment.

How It Works

  • When studying the flashcards in a given compartment you examine the flashcards sequentially and indicate success or failure.
  • When all of the flashcards from the compartment have been answered you are presented with a summary of the results and allowed to make modifications. When the summary accurately reflects your study session you save the results to the system.
  • When the results are saved all flashcards that were answered correctly are promoted to the next compartment. Flashcards that were not answered correctly are demoted to the first compartment.
  • A cardfile is complete when all flashcards are in the highest compartment. Each flashcard needs to be consecutively answered successfully the same number of times for all flashcards to be in the final compartment.

The result of the Leitner system is that you are allowed to prioritize your studying, focusing on the flashcards that are troubling you when you are keen and reviewing the easier flashcards when you want a lighter study session.


  • Selective Learning: Prioritize your studying by focusing on the proper compartment—each compartment represents a degree of knowledge. This allows you to learn what you need to learn, when you want to learn it.
  • Staggered Learning: Using the review scheduling system allows you to maintain properly spaced review sessions. Staggered learning minimizes the amount of time required to complete a cardfile and maximizes information retention.
  • Assessment: By examinining the distribution of flashcards within the various compartments you can easily gague your mastery of the subject.
​Read More

Free Flashcard Learning

Ack! I found this great learning application 😀 It’s called jMemorise. And best of all, it’s open-source software!

jMemorise is a Java application that manages your flashcards by the famous Leitner system and makes memorizing facts not only more efficient but also more fun. It manages your whole learning progress and features categories, statistics and a visually appealing and intuitive interface.

A flashcard or flash card is a piece of paper that is used in schools as a learning aid (mainly in English-speaking countries). Flashcards can bear vocabulary, historical dates, formulas, etc. The purpose of using flashcards is memorization. You write a question on each card (and an answer overleaf), test yourself on them, and sort them into groups as you learn, according to your performance.

This strategy makes selective learning possible, that is: the more difficult the flashcards in a group, the more often you review that group. The result is, you save a lot of study time.

This method was proposed by the German psychologist Sebastian Leitner in the 1970s. Pimsleur language courses are based on a similar idea.

The basic idea is to divide the cards into different decks depending on the difficulty they present to you. This is done by repetitive quizzes in which you try to answer the question out of your mind. Every time you know the correct answer to a card, it is put on the next higher card deck. If you fail at a card, it is put back to the starting deck.
[The visual representation of decks in jMemorize]

This system is combined with time schedules. Cards that have been known, are considered to be learned until a specific expiration date has passed. The higher the deck, the more further away the expiration date is set. For example might a card that has been successfully checked for the first time be scheduled to be relearned one day later again, while a card that has been correctly answered three times in a row be considered as learned for about week. As long as a card is considered learned, it won’t appear in learn sessions.

As a whole, this system manages your personal learn sessions and allows you to focus on learning, while it automatically decides which facts should be learned right now to make the most out of your time.

Interested? Check out jMemorise now – it’s free!

​Read More