Exercises, examples and other material relating to training module Q806. This topic is presented on public course Regular Expressions
Related technical and longer articlesRegular Expressions in Java
|Articles and tips on this subject||updated|
|3788||Getting more than a yes / no answer from a regular expression pattern match|
Guy walks up to me in the street and asks "Could you direct me to the Town Centre?". So I answer him "yes, I could", and walk on. Does he thank me? No - he probably thinks "what a useless half answer" or "how rude can you be", even though I completely and correctly answered his question.
It's sometimes ...
|3218||Matching a license plate or product code - Regular Expressions|
Questions from my mailbox:
1. Regular expression to accept the following form of license plate numbers. Three letters followed by between 1 and 4 digits.
2. A regular expression to accept the following product codes: Between 1 and three characters (in capitals) followed by between one and three digits.
|2804||Regular Expression Myths|
Does this look good to you?
It shows some regular expression myths that I would like to explode!
Myth 1. If you want to match a specific character, you must put it in square brackets.
WRONG ... Square Brackets are a grouping - if you're looking to match just a single specific ...
|2727||Making a Lua program run more than 10 times faster|
I made an extraordinary claim on Thursday. One of my delegates had written a program that analyzed a huge data file in a Lua script, and it was taking over half an hour to run. "Give me five minutes, and I could have that running in less that five minutes" I claimed.
It was all to do with pattern ...
|2702||First and last match with Regular Expressions|
Conventional Wisdom says that it's pointless to start a regular expression with ".*" or ".+", as this is implied within a match - regular expression matches are looking for strings that are contained anyway:
'/abc/' - contains abc
'/.*abc/' - contains anything or nothing, followed by abc
However - ...
|2608||Search and replace in Ruby - Ruby Regular Expressions|
"If you want to replace one part of a string by another in Ruby, you can use the sub method on your string object. The first parameter you give to the method is the string you want to replace, and the second is the string you want to replace it by."
OK - that's the easy bit ... but what if ....
|2563||Efficient debugging of regular expressions|
Are you a programmer? Have you ever spent *hours* looking for a very odd bug in your code that, when you find and fix it, turns out to have been so blindingly obvious that you ask "why sis it take me so LONG" ... and so does the boss! The good news is that - if the boss is a programmer - (s)he will ...
|2165||Making Regular Expressions easy to read and maintain|
Have you ever seen a long regular expression made up of so many special characters that you can't read or maintain it very easily? Something like
We offer a Regular Expression Course that will help you understand ...
|1840||Validating Credit Card Numbers|
It's standard practise for on line bookings these days to take credit or debit card details as a booking security, and we're no exception at Well House Manor - our hotel for business visitors to Melksham, Wiltshire. There are very many security issues involved, and I am not going to describe what we ...
|1305||Regular expressions made easy - building from components|
There seems to be a certain macho desire in many programmer's minds to write a single complicated regular expression to match against an input line, ignorning the structured approach that everyone accepts quite cheerfully in almost every other case. Have a look at this Python line:
wholeline = r"\d\d-...-\d\d\d\d\s+(\d\d):(\d\d):(\d\d.\d\d),\s+(-?\d+\.\d+),\s+(-?\d+\.\d+),(-?\d+\.\d+),\s+(-?\d+\.\d+),(-?\d+\.\d+),\s+(-?\d+\.\d+)"
|1230||Commenting a Perl Regular Expression|
The x modifier on the end of a Perl regular expression causes all spaces in the regular expression to be treated as comments (rather than matching exactly). This means that you can lay out your regular expressions much more cleanly.
And wherever you're allowed white space, you can add comments from ...
|672||Keeping your regular expressions simple|
There's something macho about programmers when it comes to regular expressions - so often they'll try and do the whole job in a single regular expression when doing a two stage process is much more logical, much quicker in operation, and far easier to code.
Take a requirement that came up this morning, ...
Examples from our training material
|easier.py|| making regular expressions easier to read [Python]|
|ex1.php|| Regular Expressions in PHP - from simple yes/no to ancilliary responses|
Some modules are available for download
as a sample of our material or under an Open Training Notes License
for free download from [here]
Topics covered in this module
Options for caputured output
Matching the parts of the string you don't want
When to use .* on the start of the end of a match
Using Regular Expressions to handle numbers
Other Regular Expression engines - from vi to Expect
If you are looking for a complete course and not just a information on a single subject, visit our Listing and schedule
Well House Consultants specialise in training courses in
. We run
throughout the UK (and beyond for longer courses), and
at our training centre in Melksham, Wiltshire, England.
It's surprisingly cost effective to come on our public courses -
even if you live in a different
country or continent to us
We have a technical library of over 700 books on the subjects on which we teach.
These books are available for reference at our training centre.