I wrote the following regex to parse cups' printers.conf file hoping to extract some data to process with a jar. Given the trace of the cups' printers.conf file:
<Printer AO002LSR01>
UUID urn:uuid:db0082f5-a114-36ad-6a86-ae4225c64b31
Info AO002LSR01
Location AO002LSR01
MakeModel Generic CUPS-PDF Printer
DeviceURI socket://172.100.100.4:9100
State Idle
StateTime 1612866350
Reason toner-empty-warning
Type 8450124
Accepting Yes
Shared Yes
JobSheets none none
QuotaPeriod 0
PageLimit 0
KLimit 0
OpPolicy default
ErrorPolicy retry-job
Attribute marker-colors \#000000
Attribute marker-levels 0
Attribute marker-names Black Cartridge HP CF226A
Attribute marker-types toner
Attribute marker-change-time 1612866349
</Printer>
<Printer AR000test>
UUID urn:uuid:9296f953-2df2-3ce9-5d4b-9108c5aa8b51
Info Zebra Test - Magazzino Arezzo
Location Magazzino Vestizione Arezzo
DeviceURI socket://192.168.9.5:9100
State Idle
StateTime 1471339234
Type 4
Accepting Yes
Shared Yes
JobSheets none none
QuotaPeriod 0
PageLimit 0
KLimit 0
OpPolicy default
ErrorPolicy retry-job
</Printer>
As you may guess the first "Printer" tag is matched and correctly addresses the groups MakeModel, DeviceURI, Accepting, and Shared whether the second "Printer" tag does not, since MakeModel is not present and the other groups get bypassed by the [\s\S]*? directive. What I'm aiming to do is to match all four words even if one is missing.
The regex I wrote this far is the following:
<Printer (.*)>[\s\S]*?((MakeModel) (.*))[\s\S]*?(DeviceURI) (.*)[\s\S]*?(Accepting) (.*)[\s\S]*?(Shared) (.*)[\s\S]*?<\/Printer>
I've already tried with the ? operator and the negative look ahead/behind syntax but to no avail. Also, the group should belong to the same match, since all the data should be somehow related for post processing. Could someone please help me?
Thanks