Please enable JavaScript to use regex101
/
^
r
e
g
e
x
[
\
-
_
]
?
1
0
1
$
/
i
Reg
ular
Ex
pressions
101
Upgrade to Pro
Enterprise
Community Library
How to contribute
x
PascalCase -> snake_case
Open Workspace
PCRE2 (PHP)
Substitution
Created 2024-03-03 14:14
1
Regular Expression
/
(
\b
(?'first_word'
[
A
-
Z
]
(?!
(
[
A
-
Z0
-
9
]
*
\b
|
[
[:alnum:]
]
*
_
)
(?#
the
word
isn't
in
all
caps
and
doesn't
contain
underscores)
)(?:
[
a
-
z0
-
9
]
*
)
)
)
|
(
\G
(?'trailing_word'
[
A
-
Z
]
[
a
-
z0
-
9
]
*
)
)
/
gm
Description
Works with many forms of alphanumeric PascalCase
PascalCase
Pascal
PascalCaseCase
Pascal684Case (pascal684_case)
Pas45calCase (pas45cal_case)
PascalCaseCaseCase (with as many words as you like)
PPascal (p_pascal)
PascalCCase (pascal_c_case)
What isn't matched
camelCase
words with '_' underscores in them (SCREAMING_SNAKE_CASE, Pascal_Snake_Case)
words without lowercase letters (ALLCAPS, ALL54CAPS)
Limitations
all 'Capitalized' words are matched and substituted to 'capitalized'
PascalCase with non-alphanumeric characters isn't matched
Submitted by
inesvar