Sublime Forum

Sublime Regex Snippet help

#1

I’ve recently started wring tests which require them to look something like this.

function test_a_user_can_view_their_profile() { }

I found this snippet which converts camel case to to underscores

    <snippet>
    <content><![CDATA[
    import ${1:module} from '${2:./path/}${1/(^[A-Z][a-z]+|[a-z])([A-Z])/\L\1_\2/g}';
    ]]></content>
        <tabTrigger>import</tabTrigger>
    </snippet>

I’m not familiar with snippets or Regex so I have no idea how to replace the camel case to trigger on space instead.

I have this so far

    <snippet>
        <content><![CDATA[
    function ${1:}${1/(^[A-Z][a-z]+|[a-z])([A-Z])/\L\1_\2/g}()
    {
        ${2:}
    }
    ]]></content>
        <tabTrigger>test</tabTrigger>
    </snippet>

Any help would greatly be appreciated.

0 Likes

#2

You may want to see this previous forum post, where someone is asking a question eerily similar to your own, which includes a sample of doing exactly this:

2 Likes