Camel Case

Last modified by Thomas Mortagne on 2021/03/18 11:29

cogSplits CamelCaseWords to separate words (Camel Case Words)
TypeSnippet
Category
Developed by

xwiki:XWiki.melv

Rating
0 Votes
LicenseGNU Lesser General Public License 2.1

Table of contents

Description

Code

{{velocity}}
## Assign text in Velocity script
#set ($text = 'This is MyText. Also with a LongCamelCaseWord. This is notACamelCase, though.')

## View old, before value
Old: $text

## Add space using regexp
#foreach ($i in [0..1000])
  #set ($foreach.text = $text.replaceAll('\b(\p{Upper})(\S*?\p{Lower})(\p{Upper})', '$1$2 $3'))
  #if ($foreach.text == $text)
    #break($foreach)
  #end
  #set ($text = $foreach.text)
#end

## View new value
New: $text
{{/velocity}}

Result

camelcase.png

Tags: groovy
     

Get Connected