Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
PCRE (PHP <7.3)

%
(?:\s*<PubMedPubDate\sPubStatus=\"(.*?)\"> (?:\s*<Year>(\d*?)</Year>\s)* (?:\s*<Month(?:\/)*>(\d*?)(?:</Month>)*?\s)* (?:\s*<Day(?:\/)*>(\d*?)(?:</Day>)*\s)* (?:\s*<Hour>(\d*?)</Hour>\s)* (?:\s*<Minute>(\d*?)</Minute>\s)* \s*</PubMedPubDate>)
%
imsgx

Description

PubMEd XML contains multiple date blocks, with or without Month, day, hour, minute. USAGE: while(my($pubstatus,$year,$month,$day,$hour,$minute)= $article =~ m% (?:\s*<PubMedPubDate\sPubStatus="(.?)"> (?:\s<Year>(\d*?)</Year>\s)* (?:\s*<Month(?:/)>(\d?)(?:</Month>)?\s) (?:\s*<Day(?:/)>(\d?)(?:</Day>)\s) (?:\s*<Hour>(\d*?)</Hour>\s)* (?:\s*<Minute>(\d*?)</Minute>\s)* \s*</PubMedPubDate>) %imsgx){

Submitted by Andy Reid - 9 years ago