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

2

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') }}
Calyx answered 9/9, 2014 at 10:38 Comment(0)
F
7

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

Sublime Text uses Boost regular expressions which support conditionals.

Formularize answered 17/9, 2014 at 23:6 Comment(2)
Dude, you're a rock star! Thank you so much.Calyx
For camelCaseStyle to "Camel Case Style" use this regex instead ${1/^(\w)|([A-Z])/(?1:\u\1:)(?2: \u\2\3:)/g}Perzan
M
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 :/

Mythopoeia answered 12/9, 2014 at 16:2 Comment(1)
Yup, that is exactly the problem I'm having. I can get examples of both, but cannot get them combined. :/Calyx

© 2022 - 2024 — McMap. All rights reserved.