Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex add space to camelCase - but not if a trailing upperCase letter exists

Tags:

regex

So i've found this - working code sample

\\B[A-Z])", " $1"

However I don't want it to space out things like "AccountUserID" to "Account User I D" - so basically no spacing if a trailing uppercase letter exists

Can anyone show me a better approachable way - possibly using capturing groups and a negative digit identifier.

Thanks!

like image 788
Pakk Avatar asked Dec 04 '25 15:12

Pakk


1 Answers

If lookbehind is supported then you can use:

(?<![A-Z])\B(?=[A-Z])

RegEx Demo

And replace it by just " "

like image 165
anubhava Avatar answered Dec 06 '25 06:12

anubhava