I am trying to write a SublimeText snippet for javascript import statements. I want the format to be as follows:
import MyFooBar from 'my-foo-bar';
The input to my regex is MyFooBar , and the output should be my-foo-bar . I found an answer that almost works in Regex - CamelCase in lower case with underscores :
Search
((?<=.)[AZ][a-zA-Z]*)|((?<=[a-zA-Z])\d+)
Replace
-$1$2
The answer says simply to use the javascript .toLowerCase() method for the subscript, but the Perl fragments use perl, of which I have the shortest knowledge. A quick search said that for the bottom, I can use \L at the beginning of my replacement.
/((?<=.)[AZ][a-zA-Z0-9]*)|((?<=[a-zA-Z])\d+)/\L-\1\2/g
This works on everyone but the character of the first segment, so MyFooBar becomes my-foo-bar .
I thought maybe I can run two regular expressions in a sequence, but either perl or Sublime will not recognize this.
Thoughts?
Edit:
When I say that it uses perl, I just mean that it uses the perl regex. As far as I can tell, I cannot execute arbitrary code; I can only specify a regex that perl can do.
Here is the full text of my snippet:
<snippet> <content><![CDATA[ import ${1:module} from '${2:./path/}${1/((?<=.)[AZ][a-zA-Z0-9]*)|((?<=[a-zA-Z])\d+)/\L-\1\2/g}'; ]]></content> <tabTrigger>import</tabTrigger> <scope>source.js</scope> </snippet>
source share