title: Regex match scss function / mixin
body: <p>I am trying to match a function or mixin used in an SCSS string so I may remove it but I am having a bit of trouble.</p>
  
  <p>For those unfamiliar with SCSS this is an example of the things I am trying to match (from bootstrap 4).</p>
  
  <pre><code>@mixin _assert-ascending($map, $map-name) {
    $prev-key: null;
    $prev-num: null;
      @each $key, $num in $map {
       @if $prev-num == null {
    // Do nothing
      } @else if not comparable($prev-num, $num) {
        @warn "Potentially invalid value for #{$map-name}: This map must be in ascending order, but key '#{$key}' has value #{$num} whose unit makes it incomparable to #{$prev-num}, the value of the previous key '#{$prev-key}' !";
      } @else if $prev-num &gt;= $num {
    @warn "Invalid value for #{$map-name}: This map must be in ascending order, but key '#{$key}' has value #{$num} which isn't greater than #{$prev-num}, the value of the previous key '#{$prev-key}' !";
   }
    $prev-key: $key;
    $prev-num: $num;
   }
  }
  </code></pre>
  
  <p>And a small function:</p>
  
  <pre><code>@function str-replace($string, $search, $replace: "") {
    $index: str-index($string, $search);
    @if $index {
      @return str-slice($string, 1, $index - 1) + $replace + str-replace(str-slice($string, $index + str-length($search)), $search, $replace);
    }
    @return $string;
  }
  </code></pre>
  
  <p>So far I have the following regex:</p>
  
  <pre><code>@(function|mixin)\s?[[:print:]]+\n?([^\}]+)
  </code></pre>
  
  <p>However it only matches to the first <code>}</code> that it finds which makes it fail, this is because it needs to find the last occurance of the closing curly brace.</p>
  
  <p>My thoughts are that a regex capable of matching a function definition could be adapted but I can't find a good one using my Google foo!</p>
  
  <p>Thanks in advance!</p>