Regular Expressions 101

Community Patterns

Matching Character Class Transitions (customization of \b)

2

Regular Expression
PCRE (PHP <7.3)

/
(?<CCT>(?:(?<=[A-Z])(?=[^A-Z]))|(?:(?<=[a-z])(?=[^a-z]))|(?:(?<=\d)(?=\D))|(?:(?<=[^A-Za-z\d])(?=[A-Za-z\d])))
/
g

Description

\b can be replicated as (?<=\w)(?=\W)|(?<=\W)(?=\w)

Understanding how to create these class transitions can be beneficial for several reasons. In this instance, counting the results of this regex can be used to measure randomness within strings containing multiple character classes.

Submitted by @notGeorgePBurdell - 6 years ago