title: Single regex that changes camel-case to dash-separated lowercase
body: <p>I'm trying to write a SublimeText <a href="http://sublimetext.info/docs/en/extensibility/snippets.html" rel="nofollow noreferrer">snippet</a> for javascript <code>import</code> statements.  I want the format the format to be like:</p>
  
  <pre><code>import MyFooBar from 'my-foo-bar';
  </code></pre>
  
  <p>The input to my regex is <code>MyFooBar</code>, and the output needs to be <code>my-foo-bar</code>.  I found an answer that almost works in <a href="https://stackoverflow.com/questions/20951645/regex-camelcase-to-lower-case-with-underscores">Regex - CamelCase to lower case with underscores</a>:</p>
  
  <blockquote>
    <p>Search for</p>
    
    <p><code>((?&lt;=.)[A-Z][a-zA-Z]*)|((?&lt;=[a-zA-Z])\d+)</code></p>
    
    <p>Replace with</p>
    
    <p><code>-$1$2</code></p>
  </blockquote>
  
  <p>The answer said to just use javascript's <code>.toLowerCase()</code> method for the lowercasing, but SublimeText snippets use perl, of which I have the briefest of knowledge.  A quick search said that for lowercasing, I can use <code>\L</code> at the beginning of my replacement.</p>
  
  <pre><code>/((?&lt;=.)[A-Z][a-zA-Z0-9]*)|((?&lt;=[a-zA-Z])\d+)/\L-\1\2/g
  </code></pre>
  
  <p>This works on all but the first segment's character, so <code>MyFooBar</code> becomes <code>My-foo-bar</code>.</p>
  
  <p>I thought maybe I could run two regexes in sequence, but either perl or Sublime doesn't recognize that.</p>
  
  <p>Thoughts?</p>
  
  <p>Edit:</p>
  
  <p>When I say it uses perl, I just mean it uses a perl regex.  As far as I can tell, I can't actually execute arbitrary code; I can only specify a regex that perl can execute.</p>
  
  <p>Here's the full text of my snippet:</p>
  
  <pre><code>&lt;snippet&gt;
      &lt;content&gt;&lt;![CDATA[
  import ${1:module} from '${2:./path/}${1/((?&lt;=.)[A-Z][a-zA-Z0-9]*)|((?&lt;=[a-zA-Z])\d+)/\L-\1\2/g}';
  ]]&gt;&lt;/content&gt;
      &lt;!-- Optional: Set a tabTrigger to define how to trigger the snippet --&gt;
      &lt;tabTrigger&gt;import&lt;/tabTrigger&gt;
      &lt;!-- Optional: Set a scope to limit where the snippet will trigger --&gt;
      &lt;scope&gt;source.js&lt;/scope&gt;
  &lt;/snippet&gt;
  </code></pre>