Voting

: min(one, four)?
(Example: nine)

The Note You're Voting On

wordragon at wrestingcontrol dot com
6 years ago
The documentation says:

"The character types \d, \D, \s, \S, \w, and \W may also appear in a character class, and add the characters that they match to the class."

It does not stress that other escape types may not. I wanted to split a string on either a comma (","), or a new line "\n". When my input stream began to include "\r\n", I decided to change "\n" to "\R". Unfortunately, my test string did not include a capital "R", or I might have found the problem sooner. My '/[\R,]/' was simply splitting on comma and the letter "R".

My test string...
"The Yum-Yum Company\r\n127 bernard street"

What DID work: '/(?:\R|,)+/'

["The Yum-Yum Company","127 bernard street"]

Given character classes only match one character, I can see clearly why my expectations were justifiably dashed, but hopefully this comment will save time for someone else.

I might add, this has taught me the value of PCRE_EXTRA (modifier "X"), which I have begun to use routinely now.

<< Back to user notes page

To Top