diff --git a/lib/nokogiri/html/document.rb b/lib/nokogiri/html/document.rb
index d3792bc..8fffa43 100644
--- a/lib/nokogiri/html/document.rb
+++ b/lib/nokogiri/html/document.rb
@@ -254,7 +254,7 @@ module Nokogiri
           if Nokogiri.jruby? && EncodingReader.is_jruby_without_fix?
             return EncodingReader.detect_encoding_for_jruby_without_fix(chunk)
           end
-          m = chunk.match(/\A(<\?xml[ \t\r\n]+[^>]*>)/) and
+          m = chunk.match(/\A(<\?xml[ \t\r\n][^>]*>)/) and
             return Nokogiri.XML(m[1]).encoding
 
           if Nokogiri.jruby?
-- 
2.27.0

