Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sublime snippet change case as well as replace underscores with spaces in mirrored text

I have several snippets for creating form elements in sublime text 2 for blade.

In order to make the snippets more sufficient, I would like to add the functionality to convert the case in the mirrored text to Title Case as well as separate the words with spaces instead of underscores.

This is a snippet from my snippet ;)

{{ Form::label('$1', '${1/\b(\w*)\b/\u\1/g}') }}

Right now when I type at position $1, the mirror text gets converted to title case.

So, the result in the blade document could be for example:

{{ Form::label('password', 'Password') }}

Now, I also want to change the mirror text to replace underscores with spaces and THEN convert to title case. This is the part I can't figure out.

So, instead of this:

{{ Form::label('password_confirmation', 'Password_confirmation') }}

I want to end up with this:

{{ Form::label('password_confirmation', 'Password Confirmation') }}
like image 645
narfie Avatar asked Sep 09 '14 10:09

narfie


Video Answer


1 Answers

{{ Form::label('$1', '${1/^(\w)|(_(\w))/(?1:\u\1:)(?2: \u\3:)/g}') }}

Sublime Text uses Boost regular expressions which support conditionals.

like image 147
FichteFoll Avatar answered Oct 27 '22 10:10

FichteFoll