         patterns.push(injection.patterns...)
         injected = true
 
-    patterns.forEach (pattern) =>
-      if pattern.anchored
-        anchored = true
-        regex = pattern.replaceAnchor(firstLine, position, @anchorPosition)
-      else
-        regex = pattern.regexSource
-      regexes.push regex if regex
+    anchored = false
+    regexes = _.map patterns, (pattern) =>
+      anchored = true if pattern.anchored
+      pattern.getRegex(firstLine, position, @anchorPosition)
 
     regexScanner = new OnigScanner(regexes)
     regexScanner.patterns = patterns

      endPattern = new Pattern(@grammar, { match: end, captures: endCaptures ? captures, popRule: true})
      @pushRule = new Rule(@grammar, { @scopeName, patterns, endPattern })
    @anchored = @hasAnchor()

  hasAnchor: ->
    return false unless @regexSource

  getScanner: (ruleStack, baseGrammar, position, firstLine) ->
    return scanner if scanner = @scannersByBaseGrammarName[baseGrammar.name]

    injected = false
    patterns = @getIncludedPatterns(baseGrammar)
    scopes = scopesFromStack(ruleStack)
    for injection in @injections
