Hi there I am trying to make an sublime text snippet and i would like to convert an camelCase word to snake_case. I do know there are plugins that allow you to convert string to snake_case but i want to do it through sublime text snippets.
I have a snippet like below.
<snippet>
<content><![CDATA[
/**
* ${TM_FILEPATH/^.+\/(\w+)\.php$/${1}/} belongs to many (many-to-many) ${1/^((.+)ies)|(.+[^s])s$/\u(?1$2y:$3)/}.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function $1()
{
return \$this->belongsToMany('App\\${1/^((.+)ies)|(.+[^s])s$/\u(?1$2y:$3)/}', '${TM_FILEPATH/^.+\/(\w+)\.php$/\l${1}/}_$1', '${TM_FILEPATH/^.+\/(\w+)\.php$/\l${1}/}_id', '${1/^((.+)ies)|(.+[^s])s$/\l(?1$2y:$3)/}_id');
}
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>btm</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.php</scope>
<description>Eloquent belongsToMany() (pivot) relation</description>
</snippet>
And as an output it gives me.
/**
* UserMessages belongs to many (many-to-many) Role.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function roles()
{
return $this->belongsToMany('App\Role', 'userMessages_roles', 'userMessages_id', 'role_id');
}
What i want to end up is the userMessages to be user_messages. Any idea how to accomplish that.
Many thanks.