diff --git a/Library/Homebrew/cmd/audit.rb b/Library/Homebrew/cmd/audit.rb
index 3d232125674a83db4f2522db7e55f13042218aff..a49d01e06c548b6a6757d651a6d7237177ebcee0 100644
--- a/Library/Homebrew/cmd/audit.rb
+++ b/Library/Homebrew/cmd/audit.rb
@@ -511,6 +511,7 @@ class FormulaAuditor
   end
 
   def audit_conditional_dep(dep, condition, line)
+    dep = Regexp.escape(dep)
     case condition
     when /if build\.include\? ['"]with-#{dep}['"]$/, /if build\.with\? ['"]#{dep}['"]$/
       problem %{Replace #{line.inspect} with "depends_on #{quote_dep(dep)} => :optional"}