• A hollow-core PCF composed of magnesium fluoride was proposed to identify toxic and hazardous gases. • The structure is based on the quasi-crystal arrangement of air holes. • Numerical simulation results showed that the fiber proposed in this study has a sensitivity coefficient above 50%, relatively low loss, and low dispersion. • The device is suitable for identifying toxic and dangerous gases. • The detection of which using this tool prevents combustion and explosion in the drilling process. In this paper, a hollow-core photonic crystal fiber (PCF) composed of magnesium fluoride is designed to identify toxic and hazardous gases. Its band structure is calculated using the well-known plane wave expansion method. The numerical results show that the proposed structure has a relatively wide photonic bandgap (PBG) in the wavelength range of 1 to 3.3 μm covering the near- and mid-infrared wavelength ranges. Then, by applying optical pulses with a wavelength in the range of the PBG to the proposed PCF, its propagation behavior is calculated by solving the nonlinear Schrödinger equation using the split-step Fourier method. The type of gas can be identified by observing and comparing the frequency responses of the gas-filled PCF with the absence of gas injection. Simulation results show that the fiber proposed in this study has a sensitivity coefficient of more than 50%. The low loss, low dispersion, and high accuracy of the proposed fiber make it a suitable tool for identifying toxic and dangerous gases such as methane and hydrogen sulfide in the drilling and oil exploration industry. Identifying them using this tool prevents combustion and explosion in the drilling process.