By RRg

2019-08-13 18:56:40 8 Comments

I need to identify PMID in the string and extract the ID from it. However, I am facing an issue to do this is Php.

I tried using Regex to identify PMID, but couldn't succeed

   $output = ob_get_clean();
   $arr1 = explode('}', $output);
   foreach ($arr1 as $line_){
//        if (strpos($line_, 'pmid')){
           preg_match_all('/"pmid":#(\d+)/', $line_, $matches);

Following is the data:

[{"author":"F\u00c3\u00bchrer S","pmid":"31401120","volume":"","issue":"","year":"2019","month":"Aug","journal":"Journal of molecular biology","journalabbrev":"J. Mol. Biol.","title":"Pathogenic Mutations Associated with Legius Syndrome Modify the Spred1 Surface and Are Involved in Direct Binding to the Ras Inactivator Neurofibromin.","order":"1","source":"PubMed"}
,{"author":"Yl\u00c3\u00a4-Outinen H","pmid":"31397088","volume":"","issue":"","year":"2019","month":"Aug","journal":"Molecular genetics & genomic medicine","journalabbrev":"Mol Genet Genomic Med","title":"Intestinal tumors in neurofibromatosis 1 with special reference to fatal gastrointestinal stromal tumors (GIST).","order":"2","source":"PubMed"}
,{"author":"Ahlawat S","pmid":"31396668","volume":"","issue":"","year":"2019","month":"Aug","journal":"Skeletal radiology","journalabbrev":"Skeletal Radiol.","title":"Current status and recommendations for imaging in neurofibromatosis type 1, neurofibromatosis type 2, and schwannomatosis.","order":"3","source":"PubMed"}
,{"author":"Ahlawat S","pmid":"31395668","volume":"","issue":"","year":"2019","month":"Aug","journal":"Neurology","journalabbrev":"Neurology","title":"Imaging biomarkers for malignant peripheral nerve sheath tumors in neurofibromatosis type 1.","order":"4","source":"PubMed"}
,{"pmid":"24033266","year":"2013","title":"A systematic approach to assessing the clinical significance of genetic variants.","author":"H Duzkale","clinacc":"RCV000218671","ClinicalSignificance":"benign","source":"ClinVar"}
,{"pmid":"25741868","year":"2015","title":"Standards and guidelines for the interpretation of sequence variants: a joint consensus recommendation of the American College of Medical Genetics and Genomics and the Association for Molecular Pathology.","author":"S Richards","clinacc":"RCV000218671","ClinicalSignificance":"benign","source":"Pubmed"}

The expected output is:



@Jose Rojas 2019-08-13 19:25:13

Try changing your regex to:

preg_match_all('/"pmid":"(\d+)/', $line_, $matches);

this should make the trick, but as @Alex Howansky mentioned, you could use json_decode

@Etin 2019-08-13 19:16:07

json_decode it as @Alex Howansky says.

    $data = json_decode($output);
    foreach($data as $row) {

Related Questions

Sponsored Content

36 Answered Questions

[SOLVED] How do I check if a string contains a specific word?

11 Answered Questions

[SOLVED] Regular expression to extract text between square brackets

  • 2010-03-08 17:11:33
  • ObiWanKenobi
  • 494814 View
  • 359 Score
  • 11 Answer
  • Tags:   regex

15 Answered Questions

[SOLVED] How to extract numbers from a string in Python?

27 Answered Questions

[SOLVED] How do I get (extract) a file extension in PHP?

  • 2008-10-06 11:00:02
  • e-satis
  • 561894 View
  • 697 Score
  • 27 Answer
  • Tags:   php file-extension

11 Answered Questions

[SOLVED] How to negate specific word in regex?

  • 2009-08-06 17:20:45
  • Bostone
  • 641723 View
  • 594 Score
  • 11 Answer
  • Tags:   regex

29 Answered Questions

[SOLVED] Regular expression to match a line that doesn't contain a word

10 Answered Questions

[SOLVED] How to extract a substring using regex

3 Answered Questions

[SOLVED] A regular expression to exclude a word/string

  • 2010-01-16 21:07:44
  • romiem
  • 530430 View
  • 266 Score
  • 3 Answer
  • Tags:   regex

8 Answered Questions

[SOLVED] How can I exclude one word with grep?

2 Answered Questions

[SOLVED] Serialized PHP Object not passing via POST.

Sponsored Content