October 2006
Intermediate to advanced
888 pages
16h 55m
English
Regular expressions are frequently cryptic, especially as they get longer. The x directive enables you to stretch out a regex across multiple lines; spaces and newlines are ignored, so that you can use these for indentation and readability. This also encourages the use of comments, although comments are possible even in simple regexes.
For a contrived example of a moderately complex regular expression, let’s suppose that we had a list of addresses like this:
addresses = [ "409 W Jackson Ave", "No. 27 Grande Place", "16000 Pennsylvania Avenue", "2367 St. George St.", "22 Rue Morgue", "33 Rue St. Denis", "44 Rue Zeeday", "55 Santa Monica Blvd.", "123 Main St., Apt. 234", "123 Main St., #234", "345 Euneva Avenue, ...
Read now
Unlock full access