{"record":{"id":"7358e9a0635c5e64","repo":"hashicorp/vagrant","slug":"no-virtual-machines-matched-the-regular-expression","errorCode":null,"errorMessage":"No virtual machines matched the regular expression given.","messagePattern":"No virtual machines matched the regular expression given\\.","errorType":"exception","errorClass":"Vagrant::Errors::VMNoMatchError","httpStatus":null,"severity":"error","filePath":"lib/vagrant/plugin/v1/command.rb","lineNumber":92,"sourceCode":"\n          # Require that names be an array\n          names ||= []\n          names = [names] if !names.is_a?(Array)\n\n          # First determine the proper array of VMs.\n          vms = []\n          if names.length > 0\n            names.each do |name|\n              if pattern = name[/^\\/(.+?)\\/$/, 1]\n                # This is a regular expression name, so we convert to a regular\n                # expression and allow that sort of matching.\n                regex = Regexp.new(pattern)\n\n                @env.vms.each do |name, vm|\n                  vms << vm if name =~ regex\n                end\n\n                raise Errors::VMNoMatchError if vms.empty?\n              else\n                # String name, just look for a specific VM\n                vms << @env.vms[name.to_sym]\n                raise Errors::VMNotFoundError, name: name if !vms[0]\n              end\n            end\n          else\n            vms = @env.vms_ordered\n          end\n\n          # Make sure we're only working with one VM if single target\n          if options[:single_target] && vms.length != 1\n            vm = @env.primary_vm\n            raise Errors::MultiVMTargetRequired if !vm\n            vms = [vm]\n          end\n\n          # If we asked for reversed ordering, then reverse it","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/hashicorp/vagrant/blob/35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5/lib/vagrant/plugin/v1/command.rb#L74-L110","documentation":"with_target_vms in a v1 command received a slash-wrapped regex target (`vagrant <cmd> /pattern/`), iterated all VM names in the Vagrantfile, and matched none of them (lib/vagrant/plugin/v1/command.rb:92). The pattern is compiled with Ruby's Regexp.new and is unanchored by default, so it matches anywhere in the machine name.","triggerScenarios":"For example `vagrant destroy /webserver/` in an environment whose machines are named web-1, web-2, db — zero matches raise before the command runs. Also regex metacharacter mistakes (`/web+/` matching nothing as expected) or an environment where the named group of machines was removed.","commonSituations":"Pattern written for full names when Vagrantfile uses abbreviated or hyphenated names; Vagrantfile refactored so the pattern's target machines no longer exist; copy-pasting a pattern from another project's docs.","solutions":["List the actual machine names with `vagrant status` or by reading the config.vm.define calls in the Vagrantfile","Fix the pattern — anchor it explicitly if you want prefix matching, e.g. /^web-/","Use an exact machine name instead of a regex when you only need one machine"],"exampleFix":"# before (machine names are web-1, web-2)\nvagrant destroy /webserver/\n\n# after\nvagrant destroy /web-/","handlingStrategy":"validation","validationCode":"pattern = \"web\"\nnames = env.vms.keys.map(&:to_s)\nabort \"no VM name matches /#{pattern}/; valid: #{names.join(', ')}\" unless names.any? { |n| n =~ /#{pattern}/ }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Anchor regex selectors explicitly (/^web-/) to match name prefixes deliberately","Derive patterns from actual `vagrant status` names, not from assumptions","Use exact machine names in scripts; keep regex selectors for interactive use"],"tags":["cli","regex","vm-selection","v1-plugins"],"backgroundTag":"regex-pattern-no-match","analyzedSha":"35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5","analyzedAt":"2026-08-21T13:34:32.514Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}