The sole prerequisite for this book is a familiarity with Ruby, JavaScript, or a similar language. It is for students who need to learn about regex in general, so it strives to be language-agnostic and does not rely heavily on knowledge obtained elsewhere. However, some of the examples and exercise solutions use Ruby and JavaScript as the languages of choice. If you have experience with Python, Perl, or PHP, you should be able to get by, even if you don't know Ruby or JavaScript well.
Don't let this stop you if you are learning regex for a different language; regex have some variants, but the basics are compatible across languages. Learning regex for Ruby and JavaScript will help you in any application that supports regex. Read the subsection on Variants in the Conclusion if you must learn regex for another language.
That said, you should find the regex documentation for your software and keep it close by for reference. Once you've learned the basics, use the documentation to gain proficiency with regex. In particular, rubyists should find the documentation for the Regexp class valuable, while JavaScripters need the RegExp documentation (note the capitalization). Both languages provide support for commonplace regex operations with their respective String classes.
If you are working in Ruby, Rubular is a great way to explore how regex interact with the strings you want to process. If you are working in JavaScript, Scriptular is similar. Both pages let you enter regex and sample strings to test the regex against, alter the regex options, and provide a handy quick reference. These services are so useful that we rely heavily on them to demonstrate how regex work with various strings.
Regexr is an alternative to Scriptular for JavaScript. It has some nice features, such as a graphic depiction of how your regex is interpreted.
Due to differences in the way Rubular and Scriptular work, we use Rubular for our discussions. Even if you are learning regex for JavaScript, we recommend that you use Rubular while working through this book. If you use Scriptular instead, the results may be confusing. In particular, Scriptular handles newlines differently from Rubular and this alters the results expected with some problems. Scriptular also requires the /g
option to show multiple matches on a single line.
When we talk of Rubular and Scriptular, we'll often say that a regex highlights or lights up a particular string or strings. This shorthand is another way of saying that Rubular or Scriptular highlight the indicated items when it applies a regex to some test data.
With this basic information out of the way, you are now ready to make your first dive into the world of regex. Enjoy!