Another Perl pattern matching example

In this example we recall the first few lines of Charles Dickens' wonderful classic, A Christmas Carol (copyright expired, sorry Charles). For each line, we print all the chunks consisting of consecutive characters which are not punctuation marks (periods, commas, semicolons, question marks, or explanation marks).

Notice the 'greedy' behavior of the Perl pattern matching engine, which finds the maximal sequence of characters matching a given regualar expression.

LineFragments not containing punctuation
Marley was dead: to begin with. There is no doubt whatever about that. The register of his burial was signed by the clergyman, the clerk, Marley was dead: to begin with
There is no doubt whatever about that
The register of his burial was signed by the clergyman
the clerk

the undertaker, and the chief mourner. Scrooge signed it: and Scrooge's name was good upon 'Change, for anything he chose to put his the undertaker
and the chief mourner
Scrooge signed it: and Scrooge's name was good upon 'Change
for anything he chose to put his
hand to. Old Marley was as dead as a door-nail. hand to
Old Marley was as dead as a door-nail

Mind! I don't mean to say that I know, of my own knowledge, what there is particularly dead about a door-nail. I might have been inclined, myself, Mind
I don't mean to say that I know
of my own knowledge
what there is particularly dead about a door-nail
I might have been inclined
myself

to regard a coffin-nail as the deadest piece of ironmongery in the trade. But the wisdom of our ancestors is in the simile; and my unhallowed hands to regard a coffin-nail as the deadest piece of ironmongery in the trade
But the wisdom of our ancestors is in the simile
and my unhallowed hands
shall not disturb it, or the Country's done for. You will therefore permit me to repeat, emphatically, that Marley was as dead as a door-nail. shall not disturb it
or the Country's done for
You will therefore permit me to repeat
emphatically
that Marley was as dead as a door-nail

Scrooge knew he was dead? Of course he did. How could it be otherwise? Scrooge and he were partners for I don't know how many years. Scrooge Scrooge knew he was dead
Of course he did
How could it be otherwise
Scrooge and he were partners for I don't know how many years
Scrooge
was his sole executor, his sole administrator, his sole assign, his sole residuary legatee, his sole friend and sole mourner. And even Scrooge was not was his sole executor
his sole administrator
his sole assign
his sole residuary legatee
his sole friend and sole mourner
And even Scrooge was not
so dreadfully cut up by the sad event, but that he was an excellent man of business on the very day of the funeral, and solemnised it with an so dreadfully cut up by the sad event
but that he was an excellent man of business on the very day of the funeral
and solemnised it with an
undoubted bargain. undoubted bargain

The mention of Marley's funeral brings me back to the point I started from. There is no doubt that Marley was dead. This must be distinctly The mention of Marley's funeral brings me back to the point I started from
There is no doubt that Marley was dead
This must be distinctly
understood, or nothing wonderful can come of the story I am going to relate. If we were not perfectly convinced that Hamlet's Father died before the understood
or nothing wonderful can come of the story I am going to relate
If we were not perfectly convinced that Hamlet's Father died before the
play began, there would be nothing more remarkable in his taking a stroll at night, in an easterly wind, upon his own ramparts, than there would be in play began
there would be nothing more remarkable in his taking a stroll at night
in an easterly wind
upon his own ramparts
than there would be in
any other middle-aged gentleman rashly turning out after dark in a breezy spot -- say Saint Paul's Churchyard for instance -- literally to astonish his any other middle-aged gentleman rashly turning out after dark in a breezy spot -- say Saint Paul's Churchyard for instance -- literally to astonish his
son's weak mind. son's weak mind

Scrooge never painted out Old Marley's name. There it stood, years afterwards, above the warehouse door: Scrooge and Marley. The firm was Scrooge never painted out Old Marley's name
There it stood
years afterwards
above the warehouse door: Scrooge and Marley
The firm was
known as Scrooge and Marley. Sometimes people new to the business called Scrooge Scrooge, and sometimes Marley, but he answered to both known as Scrooge and Marley
Sometimes people new to the business called Scrooge Scrooge
and sometimes Marley
but he answered to both
names: it was all the same to him. names: it was all the same to him

Oh! But he was a tight-fisted hand at the grind-stone, Scrooge! a squeezing, wrenching, grasping, scraping, clutching, covetous, old sinner! Hard Oh
But he was a tight-fisted hand at the grind-stone
Scrooge
a squeezing
wrenching
grasping
scraping
clutching
covetous
old sinner
Hard
and sharp as flint, from which no steel had ever struck out generous fire; secret, and self-contained, and solitary as an oyster. The cold within him and sharp as flint
from which no steel had ever struck out generous fire
secret
and self-contained
and solitary as an oyster
The cold within him
froze his old features, nipped his pointed nose, shriveled his cheek, stiffened his gait; made his eyes red, his thin lips blue and spoke out shrewdly in froze his old features
nipped his pointed nose
shriveled his cheek
stiffened his gait
made his eyes red
his thin lips blue and spoke out shrewdly in
his grating voice. A frosty rime was on his head, and on his eyebrows, and his wiry chin. He carried his own low temperature always about with him; his grating voice
A frosty rime was on his head
and on his eyebrows
and his wiry chin
He carried his own low temperature always about with him

he iced his office in the dogdays; and didn't thaw it one degree at Christmas. he iced his office in the dogdays
and didn't thaw it one degree at Christmas

External heat and cold had little influence on Scrooge. No warmth could warm, no wintry weather chill him. No wind that blew was bitterer than he, External heat and cold had little influence on Scrooge
No warmth could warm
no wintry weather chill him
No wind that blew was bitterer than he

no falling snow was more intent upon its purpose, no pelting rain less open to entreaty. Foul weather didn't know where to have him. The heaviest no falling snow was more intent upon its purpose
no pelting rain less open to entreaty
Foul weather didn't know where to have him
The heaviest
rain, and snow, and hail, and sleet, could boast of the advantage over him in only one respect. They often "came down" handsomely, and Scrooge rain
and snow
and hail
and sleet
could boast of the advantage over him in only one respect
They often "came down" handsomely
and Scrooge
never did. never did