 enhancedRegexpReplace = (str, left, right) ->
   str = str.replace left, right
   caseChangeExpr = /\\([UL]).*?(\\E|$)/
-  if right.search(caseChangeExpr) != -1
-    while str.search(caseChangeExpr) != -1
+  if caseChangeExpr.test right
+    while caseChangeExpr.test str
       str = str.replace caseChangeExpr, (text) ->
         if text.slice(0, 2) == '\\U'
           caseChange = String::toUpperCase

  query: (pattern) ->
    s = new Script
    for k, v of @mapping
      s.mapping[k] = v unless k.search(pattern) == -1
    s

  queryPrevious: (previous) ->

      return null
    return x
  calculate: (spelling) ->
    if @pattern.test spelling.text
      []
    else
      [spelling]
