Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
Python, Lua and Tcl - public course schedule [here]
Private courses on your site - see [here]
Please ask about maintenance training for Perl, PHP, Java, C, C++, Ruby, MySQL and Linux / Tomcat systems

Phone System reconfiguration 11.1.2018 and 12.1.2018 - we are on email but incoming phone not available all the time

Well House Consultants
You are on the site of Well House Consultants who provide Open Source Training Courses and business hotel accommodation. You are welcome to browse and use our resources subject to our copyright statement and to add in links from your pages to ours.
Other subject areas - resources
Java Resources
Well House Manor Resources
Perl Resources
Python Resources
PHP Resources
Object Orientation and General topics
MySQL Resources
Linux / LAMP / Tomcat Resources
Well House Consultants Resources
Extras Resources
C and C++ Resources
Ruby Resources
Tcl/Tk Resources
Web and Intranet Resources
Ruby module R109
Strings and Regular Expressions
Exercises, examples and other material relating to training module R109. This topic is presented on public courses Learning to program in Ruby, Ruby Programming

Strings and regular expressions are the core of most Ruby applications and you'll be thrilled at the broad scope of methods available to you.
Related technical and longer articles
Pattern Matching - a primer on regular Expressions
Ruby Regular Expressions
String Functions in Ruby

Articles and tips on this subjectupdated
4549Clarrissa-Marybelle - too long to really fit?
Would you christen your child Clarissa-MaryBelle? No, neither would I, but someone might - and there's a name that's so long it won't fit into boxes on forms. When programming, there's a need to format things to line up, and in a ixed with font / plain text data file, that's done withspae pading - ...
4505Regular Expressions for the petrified - in Ruby
Regular Expressions ... frighten ... newcomers at their apparent peverseness and complexity. But they need not - regular expressions are made up of just a handful of types of elements and once you realise this, they become easy! The background is that you want to ask is a string of text looks like ...
4388Global Regular Expression matching in Ruby (using scan)
Regular expression 'engines' start at the left of an input string they're matching against, and counts are usually greedy, so by default they return "leftmost, longest" matches - which works for what users want in most cases. However, sometimes you may want to work through all (non-overlapping) matches ...
2980Ruby - examples of regular expressions, inheritance and polymorphism
With delegates on public Well House Consultants courses staying in our on-site accommodation, there's time for them to learn a lot more about each other's applications and get a far wider view of the uses of the subject they're with us to learn. There's time for the delegate who wants to extend practicals ...
3758Ruby - standard operators are overloaded. Perl - they are not
Ruby has been described to me as "What Perl 5.5 should have been", but that statement is a severe dis-service to Ruby, and to Perl. Ruby is a new language, and if you're moving into Ruby from Perl, you'll do best not to assume even the basics from Perl. A lot has been learend from Perl, for sure, ...
3757Ruby - a teaching example showing many of the language features in short but useful program
Although the main publicity and driver for the Ruby language has been the Rails web framework (see previous article here), it's an excellent data manipulation language too - with many of the short and efficient coding techniques that you would have available to you in Perl, yet additionally with an object ...
3621Matching regular expressions, and substitutions, in Ruby
A stranger comes up to me as I'm walking the dogs and asks me "Do you know the way to the Town Centre?". "Yes" I answer, and walk on. I've answered his question, but he probably meant to ask me to give him directions to the town center and my answer isn't really useful to him - it's not enough. It's ...
3424Divide 10000 by 17. Do you get 588.235294117647, 588.24 or 588? - Ruby and PHP
If you divide £10,000 between 17 lucky children, each gets £588.23 ... but if you divide the number 10,000 by the number 17, you get 588.235294117647. How do you format the data to the appropriate number of decimal places? In Ruby, you can use the % operator on a string - which is an alias ...
2623Object Oriented Ruby - new examples
We had an "object oriented Ruby" morning on today's course. "But everything's an object in Ruby" you'll tell me and you're sort of right (we could argue about what symbols and code blocks are), but there are certain elements of object orientation which require specific coverage. Here are links to three ...
2621Ruby collections and strings - some new examples
From yesterday's Ruby course - a whole set of new examples on Ruby collections - arrays (which are ordered lists) and hashes (which are unordered). In other words, you look somethng up in an array by its position number, whereas you look something up in a hash based on its unique key, and the way it's ...
2614Neatly formatting results into a table
Would you like to produce a neat table of results, with the columns just wide enough to take the data? That sounds straightforward, but you can't output anything until you've looked through all the lines to see how long each of them will be. I was talking about this algorithm today, and this evening ...
2608Search 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 .... If ...
2295The dog is not in trouble
"I know I put my papers somewhere" I said to Lisa [wife], and Gypsy [dog] goes off and whimpers in the corner, looking very guilty. So had she [dog] taken the papers and chewed them? That wasn't the case - she had heard the word "no" (or rather "know") in what I said, and had taken it that she was ...
2293Regular Expressions in Ruby
Ruby has a wide variety of string handling methods, and a very strong regular expression engine. In one of the example I wrote today ([link] Regular Expression Example in Ruby) I've included a primer on the elements of a Ruby Regular expression as well as sample source code - showing you how you can ...
1887Ruby Programming Course - Saturday and Sunday
We're so busy during the week at the moment that I'm running an extra Ruby Course this weekend. The main use of Ruby is within "Ruby on Rails", but our course concentrates on the language itself and so it's suitable for people who are using RSpec, cucumber and Watir as well as Rails. Here are some ...
1891Ruby to access web services
If you want to use a Ruby program to access an RSS feed (or some other XML or HTML data), you can start with the standard Net::HTTP module ... full (working, tested) example here. That example "just" uses a Get method to get an RSS feed of the latest posts to the First Great Western Coffee Shop Forum ...
1875What are exceptions - Python based answer
How do you check for run time errors in your program? You'll include tests with if statements in almost every program you write, to ensure that user entered data is reasonable / as you would expect ... but you will also need to do more that that. You'll need to check whether a system function has run ...
1588String interpretation in Ruby
Ruby's rather clever in terms or how it handles string interpretation. Since variable names only start with special characters sometimes, it can't use Perl's trick of making the $ and @ character special in a string. So instead it uses a #{.....} notation. For example: puts "Tocker is #{tocker}" uses ...
1305Regular 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+)" Impressive, ...
1195Regular Express Primer
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 ...
987Ruby v Perl - interpollating variables
When printing in Perl, you can drop a variable into a double quoted string ant it will be interpretter for you: "--- $number ---" If you want to perform an operation on the variable, though, it's not as easy - you have to come out of the double quoted string, do the calculation, then start another ...
986puts - opposite of chomp in Ruby
In Ruby, the chomp method removes the last character of a string if it's a line separator. The puts method adds a new line character on to the output unless there's one already present. In Perl and other languages, a great deal of time and mental agility is expended in remembering where there are (and ...
970String duplication - x in Perl, * in Python and Ruby
In Python and Ruby you can duplicate a string by running the multiply operator (*) on a string object, and in perl you can use the x operator. There have been many times when I've looked at this facility and said to myself "very nice, but isn't that a feature looking for a benefit" - in other words, ...
Examples from our training material
bc   Some String Handling
d4_1   Using a string as a collection
d4_6   Formatted printing
d4_7   Running a piped command via backquotes
d4_8   Regular Expression (including documenation)
e2   Embedded variables in strings
finder   search, search / replace, search / execute / replace
globalmatch   Scan for global matches
heredocs.rb   Here Documents in Ruby
ii   Formatting example - splitting money between nieces and nephews
kiddos   Formatting a table of data
kids   Formatting values in Ruby
mlre.rb   Commenting a regular expression
names   formatting - adjust for longest string
pareea   Class for email addresses / regex for splitting and checking
pc   extracting sections from a match
regex_sub.rb   Regular Expression Substitution
rex1.rb   Ruby regular expression demo
rex2.rb   Splitting at a regular expression
se1   Regular Expression Primer Example
shalt   the compact method removes nil elements from an array
sop.rb   + and * on strings in Ruby
stdo.rb   Using some of ruby's string methods
str_types.rb   Ways of writing a string
summatelse   Regular Expression Alternative Example
vest   Cleaning up a phone number and checking a postcode
Background information
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
Anchors, literals, character groups and counts.
Matching in Ruby.
Modifiers i, o, x and m.
Pattern matching variables.
Complete learning
If you are looking for a complete course and not just a information on a single subject, visit our Listing and schedule page.

Well House Consultants specialise in training courses in Ruby, Lua, Python, Perl, PHP, and MySQL. We run Private Courses throughout the UK (and beyond for longer courses), and Public Courses 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.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2018: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/resources/R109.html • PAGE BUILT: Mon Feb 8 18:55:24 2016 • BUILD SYSTEM: WomanWithCat