I can separate data from the plain text below with Regex.
Plain text:
190.A 42-year-old male patient has been delivered to a hospital in a grave condition with dyspnea, cough with expectoration of purulent sputum, fever up to 39,5 oC.The ?rst symptoms appeared 3 weeks ago. Two weeks ago, a local therapist diagnosed him wi- th acute right-sided pneumonia. Over the last 3 days, the patient’s condition deteriorated: there was a progress of dyspnea, weakness, lack of appetite. Chest radiography con?rms a rounded shadow in the lower lobe of the right lung with a horizontal?uid level, the right si- nus is not clearly visualized. What is the most likely diagnosis? A.Abscess of the right lung B.Acute pleuropneumonia C.Right pulmonary empyema D.Atelectasis of the right lung E.Pleural effusion 191.An 11-year-old boy complains of general weakness, fever up to 38,2 oC, pain and swelli- ng of the knee joints, feeling of irregular heartbeat. 3 weeks ago, the child had quinsy. Knee joints are swollen, the overlying skin and skin of the knee region is reddened, local temperature is increased, movements are li- mited. Heart sounds are muf?ed, extrasystole is present, auscultation reveals apical systolic murmur that is not conducted to the left ingui- nal region. ESR is 38 mm/h. CRP is 2+, anti- streptolysin O titre - 40 0. What is the most likely diagnosis? A.Acute rheumatic fever B.Vegetative dysfunction C.Non-rheumatic carditis D.Juvenile rheumatoid arthritis E.Reactive arthritis 192.A 28-year-old male patient complains of sour regurgitation, cough and heartburn that occurs every day after having meals, when bending forward or lying down. These problems have been observed for 4 years. Objective status and laboratory values are normal. FEGDS revealed endoesophagitis. What is the leading factor in the development of this disease? A.Failure of the lower esophageal sphincter B.Hypersecretion of hydrochloric acid C.Duodeno-gastric re?ux D.Hypergastrinemia E.Helicobacter pylori infection 193.On admission a 35-year-old female reports acute abdominal pain, fever up to 38,8 oC, mucopurulent discharges. The pati- ent is nulliparous, has a history of 2 arti?cial abortions. The patient is unmarried, has sexual Krok 2 Medicine 20 14 24 contacts. Gynecological examination reveals no uterus changes. Appendages are enlarged, bilaterally painful. There is profuse purulent vaginal discharge. What study is required to con?rm the diagnosis? A.Bacteriologic and bacteriascopic studies B.Hysteroscopy C.Curettage of uterine cavity D.Vaginoscopy E.Laparoscopy
What did I do for this?
For the question section:
/(\d+)\.\s*([A-Z].*?)\s+([A-Z]\..*?)(?=\d+\.\s*[A-Z]|$)/s
For the options of question section:
/\s+(?=[A-Z0-9][,.:])
PHP:
$soruAlimPattern = [
'q&a' => '/(\d+)\.\s*([A-Z].*?)\s+([A-Z]\..*?)(?=\d+\.\s*[A-Z]|$)/s',
'answers' => '/\s+(?=[A-Z0-9][,.:])/'
];
$res = [];
if (preg_match_all($soruAlimPattern['q&a'], $temizSoruCikisi, $out, PREG_SET_ORDER) > 0) {
foreach ($out AS $k => $v) {
// remove the full match ($0)
$res[$k] = array_slice($v, 1, 3);
// split the answers
$res[$k][2] = preg_split($soruAlimPattern['answers'], $res[$k][2]);
}
}
$sorularJsonKodlaniyor = json_encode($res);
[...]
I can distinguish between question and question options, but is it possible to use a single Regex code instead of 2 different Regex? I don't know how quality the PHP code is but it works.
My problem:
1. Sometimes there are unidentifiable letters in the question and these
undefined characters are indicated with a question mark. For
example: `fever up to 39,5 oC.The ?rst symptoms` or `..39,5 oC.The ?rst symptoms..`
2. Due to the numerical values in the question, the Regex code divides the question in half. For example: `... anti- streptolysin O titre - 40 0. What is the most likely diagnosis? ` In fact, the question divides the question because of the number "zero".
Expected JSON Format:
[
{
"question": "90.A 42-year-old male patient has been delivered to a hospital in a grave condition with dyspnea, cough with expectoration of purulent sputum, fever up to 39,5 oC.The ?rst symptoms appeared 3 weeks ago. Two weeks ago, a local therapist diagnosed him wi- th acute right-sided pneumonia. Over the last 3 days, the patient’s condition deteriorated: there was a progress of dyspnea, weakness, lack of appetite. Chest radiography con?rms a rounded shadow in the lower lobe of the right lung with a horizontal?uid level, the right si- nus is not clearly visualized. What is the most likely diagnosis? ",
"answers": [
"A.Abscess of the right lung ",
"B.Acute pleuropneumonia ",
"C.Right pulmonary empyema ",
"D.Atelectasis of the right lung ",
"E.Pleural effusion 1"
]
},
{
"question": "91.An 11-year-old boy complains of general weakness, fever up to 38,2 oC, pain and swelli- ng of the knee joints, feeling of irregular heartbeat. 3 weeks ago, the child had quinsy. Knee joints are swollen, the overlying skin and skin of the knee region is reddened, local temperature is increased, movements are li- mited. Heart sounds are muf?ed, extrasystole is present, auscultation reveals apical systolic murmur that is not conducted to the left ingui- nal region. ESR is 38 mm/h. CRP is 2+, anti- streptolysin O titre - 40 0. What is the most likely diagnosis? ",
"answers": [
"A.Acute rheumatic fever ",
"B.Vegetative dysfunction ",
"C.Non-rheumatic carditis ",
"D.Juvenile rheumatoid arthritis ",
"E.Reactive arthritis 1"
]
},
{
"question": "92.A 28-year-old male patient complains of sour regurgitation, cough and heartburn that occurs every day after having meals, when bending forward or lying down. These problems have been observed for 4 years. Objective status and laboratory values are normal. FEGDS revealed endoesophagitis. What is the leading factor in the development of this disease? ",
"answers": [
"A.Failure of the lower esophageal sphincter ",
"B.Hypersecretion of hydrochloric acid ",
"C.Duodeno-gastric re?ux ",
"D.Hypergastrinemia ",
"E.Helicobacter pylori infection 1"
]
},
{
"question": "93.On admission a 35-year-old female reports acute abdominal pain, fever up to 38,8 oC, mucopurulent discharges. The pati- ent is nulliparous, has a history of 2 arti?cial abortions. The patient is unmarried, has sexual Krok 2 Medicine 20 14 24 contacts. Gynecological examination reveals no uterus changes. Appendages are enlarged, bilaterally painful. There is profuse purulent vaginal discharge. What study is required to con?rm the diagnosis? ",
"answers": [
"A.Bacteriologic and bacteriascopic studies ",
"B.Hysteroscopy ",
"C.Curettage of uterine cavity ",
"D.Vaginoscopy ",
"E.Laparoscopy 1"
]
}
]
How can I overcome these problems?