문제

I'm writing a sublimetext snippet, and I want to mirror a field, but get the mirrored field as a lowercase while the original field is in Title case.

getUser ('username', function(err, user){});
   ^^^^                            ^^^^

Here it says that I could use perl regex but I don't know either enough to figure out
what would be the appropriate regex to achieve this?

get${1:User}('',function(err,${1/???/g}){});
도움이 되었습니까?

해결책

Instead of doing a simple replacement, you need a format string to your regex, as discussed in the snippets reference. So, your snippet should look like this:

<snippet>
    <content><![CDATA[
get${1:User} ('$2', function(err, ${1/(.*)/\L\1\E/i}){$0});
]]></content>
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    <tabTrigger>get</tabTrigger>
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <scope>source.c</scope>
</snippet>

The regex matches all possible characters in variable $1 (except newlines) and replaces it with itself but formats it in all lowercase (\L begins lowercasing, \1 is the first capture group, and \E ends it). After it does that, hitting Tab moves to $2, so you can enter that value if you wish. Hitting Tab once more puts the cursor between the {} curly braces.

Make sure you set the <scope> to the appropriate language.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top