6

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') }}
narfie
  • 493
  • 1
  • 7
  • 16

2 Answers2

7

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

Sublime Text uses Boost regular expressions which support conditionals.

FichteFoll
  • 663
  • 1
  • 6
  • 12
0
<snippet>
    <content><![CDATA[
<div class="form-group">
    {!! Form::label('${1:text}', '${1/(^|_)(.)/$1\u$2/g}:') !!}
    {!! Form::text('${1:text}', null, ['class' => 'form-control']) !!}
</div>
]]></content>
<!-- {!! Form::label('${1:text}', '${1/_/\ /-/g}:') !!} -->
<tabTrigger>textfield</tabTrigger>

The above gets close, but not quite there. It capitalizes the letter after the underscore. The commented out line replaces underscores with spaces... I just can't figure out how to combine the two of them :/

  • Yup, that is exactly the problem I'm having. I can get examples of both, but cannot get them combined. :/ – narfie Sep 16 '14 at 08:25