问题
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') }}
回答1:
{{ Form::label('$1', '${1/^(\w)|(_(\w))/(?1:\u\1:)(?2: \u\3:)/g}') }}
Sublime Text uses Boost regular expressions which support conditionals.
回答2:
<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 :/
来源:https://stackoverflow.com/questions/25742517/sublime-snippet-change-case-as-well-as-replace-underscores-with-spaces-in-mirror