A chemometrically optimized isolation procedure combined with gas chromatography-mass spectrometry detection technique has been proposed for quantitative determination of trace levels of nitrosamines in gastric juice samples of patients with the gastrointestinal tract problems. The extraction conditions of each nitrosamine were optimized using regression modelling based on central composite design. The extraction conditions for all nitrosamines were selected to be 10.7 min for extraction time, 4.2 for pH and 23 for 2-propanol percentage in extraction solution. The obtained recoveries of nitrosamines ranged from 94.0 (NDMA) to 99.3 (NDPheA) %, and the precision of this method, as indicated by the relative standard deviations was within the range of 0.7 (NDPheA) and 2.6 (NDMA) %. The detection limits obtained from calculations by using GC-MS results based on S/N=3 were found within the range from 0.3 to 1.1 pg/mL. Total nitrosamine concentrations were found at the highest concentration up to 2431.12 pg/mL in cancer patients, whereas they were found at the lowest concentration down to 12.18 pg/mL in gastritis patients. The classification results of the gastric juice samples in different patient groups were very satisfactory, allowing 100% of patients to be correctly grouped. A new mathematical model has been developed allowing for the classification of gastric juices with a 93.1% success rate based on just the ratio of MNPIZ to DNPIZ. The ratio of MNPIZ to DNPIZ might be considered as a biomarker for the classification of gastric juices of patients and might act as an indicator of increased risk for stomach cancer.