regex pattern to extract repeating groups
On 28/08/2018 7:09 AM, John Pote wrote:
> On 26/08/2018 00:55, Malcolm wrote:
>> I am trying to understand why regex is not extracting all of the
>> characters between two delimiters.
>> The complete string is the xmp IFD data extracted from a .CR2 image
>> I do have a work around, but it's messy and possibly not future proof.
> Do you mean future proof your workaround or Cannon's .CR2 raw image
> files might change? I guess .CR2's won't change but Cannon have
> brought out the new .CR3 raw image file for which I needed to upgrade
> my photo editing suit (at least I didn't but used their tool to
> convert .CR3s from the camera to the digital negative format which
> many photo editors can handle.) Can send you sample .CR3 if you want
> to compare.
The application is for personal use. Why I'm familiar with python
generally (and thanks to all who post code and answer questions), this
is the first time I have used structs to read a binary file, xml parsers
to parse some of the RFD contents and re.
I have now discovered that when print the return of re.search that the
matched='truncates the matched characters'.? To see/get all found
characters I need to use the span as indexes to the original string. I'm
not sure if this is mentioned in the re documentation. But all the
samples I've seen on the web use only small strings. This was the cause
of my question.
data = '''
re_pattern =r'( *<dc:.*</dc:)' x = re.search(re_pattern, data, re.DOTALL)
print(data[x.span() : x.span()])
<_sre.SRE_Match object; span=(1, 89), match=' <dc:creator>\n <rdf:Seq>\n <rdf:li>abcd>
By future proofing: At the moment I'm testing code against one .CR2
image. My wish at the moment is that my code will work on all of my .CR2
images from? different cameras. When I upgrade my camera(s) to one(s)
that produces .CR3 images I will, no doubt, need to re test my code.
All I trying to do really is to extract some metadata and a
thumbnail/preview jpg using python instead of relying on subprocess and
exiftool/ exiv2.? trying to speed things up. Oh and I got side tracked
on learning something new.
the full RDF-XMP extracted truncated
xml_data = '''<rdf:RDF
? <rdf:Description rdf:about=""
?? Iptc4xmpCore:Location="Binna Burra"
?? photoshop:City="Lamington National Park"
?? tiff:Artist="Malcolm Blake"
???? <rdf:li>Malcolm Blake</rdf:li>
???? <rdf:li xml:lang="x-default">Malcolm Blake</rdf:li>
???? <rdf:li>AUS, Arthur Grooms Cottage, Australia, Binna Burra,
Lamington National Park, Qld</rdf:li>