Pakk February 2016

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

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!

Answers


anubhava February 2016

If lookbehind is supported then you can use:

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

RegEx Demo

And replace it by just " "


alpha bravo February 2016

Use this pattern :

(?<=[a-z])(?=[A-Z])

and replace with a white space
Demo

Post Status

Asked in February 2016
Viewed 2,910 times
Voted 12
Answered 2 times

Search




Leave an answer