Main Content
Regular Express Primer Archive - Originally posted on "The Horse's Mouth" - 2007-05-20 12:58:33 - Graham Ellis
Over the years I've been teaching people about Regular Expressions, I've learnt what does and doesn't work in such tuition. A casual question I saw yesterday got me writing, and I've just posted up a new technical article to the solution centre - see here (it will open in a separate window).
It's amazing - truly amazing - how often there's a code requirement to say "does this look like that" and that's exactly what regular expressions do. In fact, I added an extra markup facility to the solution centre as I was writing the article as I wanted an extra way to emphasise and - guess what - the methodolgy I used was a regular expression!
There are full tables of Regular Expression elements on our web site too - see here as a starter, and we even offer regular expression mousemats for sale at, of course, a very reasonable cost!
Some other articles
Y108 - String Handling Prining a pound sign from Python AND running from the command line at the same time Python formatting update - including named completions Command line parameter handling in Python via the argparse module Python - comparison of old and new string formatters Identifying and clearing denial of service attacks on your Apache server Formatting options in Python Why are bus fares so high? Collections in Python - list tuple dict and string. Formatting output - why we need to, and first Python example Backquote, backtic, str and repr in Python - conversion object to string Teaching dilemma - old tricks and techniques, or recent enhancements? Python string formatting - the move from % to str.format Formatting output in Python through str.format Matching a license plate or product code - Regular Expressions Matching to a string - what if it matches in many possible ways? Python - splitting and joining strings Formatted Printing in Python Running operating system commands from your Python program Regular Expressions in Python Flexible search and replace in Python Pound Sign in Python Program Strings as collections in Python Python Regular Expressions Underlining in Perl and Python - the x and * operator in use Python - formatting objects This article Python - two different splits String duplication - x in Perl, * in Python and Ruby Splitting Pythons in Bradford Matching within multiline strings, and ignoring case in regular expressions Pieces of Python Breaking bread The fencepost problem Python printf Splitting the difference The backtick operator in Python and Perl T247 - Advanced Regular Expressions Regular Expression Substitution - Tcl Regular expression for 6 digits OR 25 digits Sparse and Greedy matching - Tcl 8.4 Tcl / regsub - changing a string and using interesting bits Ignore case in Regular Expression Regular expressions made easy - building from components This article Matching within multiline strings, and ignoring case in regular expressions R109 - Strings and Regular Expressions Clarrissa-Marybelle - too long to really fit? Regular Expressions for the petrified - in Ruby Global Regular Expression matching in Ruby (using scan) Ruby - standard operators are overloaded. Perl - they are not Ruby - a teaching example showing many of the language features in short but useful program Matching regular expressions, and substitutions, in Ruby Divide 10000 by 17. Do you get 588.235294117647, 588.24 or 588? - Ruby and PHP Ruby - examples of regular expressions, inheritance and polymorphism Object Oriented Ruby - new examples Ruby collections and strings - some new examples Neatly formatting results into a table Search and replace in Ruby - Ruby Regular Expressions The dog is not in trouble Regular Expressions in Ruby Ruby to access web services Ruby Programming Course - Saturday and Sunday What are exceptions - Python based answer String interpretation in Ruby Regular expressions made easy - building from components This article Ruby v Perl - interpollating variables puts - opposite of chomp in Ruby String duplication - x in Perl, * in Python and Ruby Q801 - What are Regular Expressions? Regex Reference sheet Regular Expressions for the petrified - in Ruby Learning about Regular Expressions in C through examples Efficient debugging of regular expressions This article P205 - Initial String Handling Sample answers to training course exercises - available on our web site Dark mornings, dog update, and Python and Lua courses before Christmas Using Perl to generate multiple reports from a HUGE file, efficiently Single and double quotes strings in Perl - what is the difference? Lots of ways of doing it in Perl - printing out answers Removing the new line with chop or chomp in Perl - what is the difference? Are you learning Perl? Some more examples for you! Intelligent Matching in Perl Perl - skip the classics and use regular expressions Seven new intermediate Perl examples String matching in Perl with Regular Expressions Underlining in Perl and Python - the x and * operator in use This article Ruby v Perl - interpollating variables String duplication - x in Perl, * in Python and Ruby The backtick operator in Python and Perl x operator in Perl Here documents J816 - Regular Expressions in Java This article H107 - String Handling in PHP Splitting the difference with PHP Setting up strings in PHP Solution looking for a problem? Lookahead and Lookbehind More than just matching with a regular expression in PHP Getting more than a yes / no answer from a regular expression pattern match Learning to program in PHP - Regular Expression and Associative Array examples Regular Expression modifiers in PHP - summary table PHP - moving from ereg to preg for regular expressions Divide 10000 by 17. Do you get 588.235294117647, 588.24 or 588? - Ruby and PHP Handling (expanding) tabs in PHP Curly braces within double quoted strings in PHP Handling nasty characters - Perl, PHP, Python, Tcl, Lua Making Regular Expressions easy to read and maintain Finding variations on a surname Regular Expressions in PHP Regular expression for 6 digits OR 25 digits Do not SHOUT and do not whisper Short and sweet and sticky - PHP form input A taster PHP expression ... Ignore case in Regular Expression This article PHP Regular expression to extrtact link and text Date conversion - PHP Looking ahead and behind in a Regular Expression Evaluating arithmetic expressions in configuration files How similar are two words Don't expose your regular expressions Robust PHP user inputs PHP - dividing a string up into pieces The fencepost problem Converting between acres and hectares Running a Perl script within a PHP page Splitting the difference PHP Magic Quotes the array returned by preg_match_all PHP and natural sorting Here documents