// include the latest version of the regex crate in your Cargo.toml
extern crate regex;
use regex::Regex;
fn main() {
let regex = Regex::new(r"(?ms)<PNR>([\w]+)<\/PNR>
").unwrap();
let string = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>
<EGE_Booking>
<TripID>1004-3637-360</TripID>
<RecordLocator>1004-3637-360</RecordLocator>
<Travelers>
<Traveler>
<PerCode>13593199</PerCode>
<FirstName>Claude</FirstName>
<LastName>Christensson</LastName>
<ContactDetails>
<Email>claude.christensson@wirelesscar.com</Email>
<MobilePhone>46765537005</MobilePhone>
</ContactDetails>
<TravellerCostCenter>
<CostCenter Code=\"CC3\">
<Label>Employee ID</Label>
<Value>56524</Value>
</CostCenter>
<CostCenter Code=\"CC4\">
<Label>Global Department code</Label>
<Value>DI43400</Value>
</CostCenter>
</TravellerCostCenter>
</Traveler>
</Travelers>
<Segments>
<HotelSegment>
<HOTEL>
<TripItemID>5a7dc8f971ac0163f7563e7e</TripItemID>
<PNR>ABC1DS</PNR>
<Status>V</Status>
<CheckInDate>2018-02-13</CheckInDate>
<CheckOutDate>2018-02-14</CheckOutDate>
<Vendor SupplierType=\"11281422\">Genting Hotel</Vendor>
<PropertyName>Genting Hotel</PropertyName>
<Location>
<Name>Pendigo Way, England, B40 1PU</Name>
<City>Birmingham</City>
<Country Code=\"GBR\">Storbritannien</Country>
</Location>
<ConfirmationCode>982674693</ConfirmationCode>
<Cost>
<Amount>751.08</Amount>
<Currency Code=\"SEK\">Swedish Krona</Currency>
</Cost>
<OutOfPolicyReasons/>
</HOTEL>
<HOTEL>
<TripItemID>5a7dc8f971ac0163f7563e7e</TripItemID>
<PNR>55545261643</PNR>
<Status>V</Status>
<CheckInDate>2018-02-13</CheckInDate>
<CheckOutDate>2018-02-14</CheckOutDate>
<Vendor SupplierType=\"11281422\">Genting Hotel</Vendor>
<PropertyName>Genting Hotel</PropertyName>
<Location>
<Name>Pendigo Way, England, B40 1PU</Name>
<City>Birmingham</City>
<Country Code=\"GBR\">Storbritannien</Country>
</Location>
<ConfirmationCode>982674693</ConfirmationCode>
<Cost>
<Amount>751.08</Amount>
<Currency Code=\"SEK\">Swedish Krona</Currency>
</Cost>
<OutOfPolicyReasons/>
</HOTEL>
</HotelSegment>
</Segments>
<Invoicing>
<CompanyCode>28781</CompanyCode>
<ClientNumber>28781</ClientNumber>
<ClientRequisition>claude.christensson@wirelesscar.com</ClientRequisition>
<ClientReference>689100277</ClientReference>
<ClientCostCenter>
<CostCenter Code=\"CC1\">
<Label>Legal Entity</Label>
<Value>WirelessCar Sweden AB</Value>
</CostCenter>
<CostCenter Code=\"CC2\">
<Label>Cost Center</Label>
<Value>989502</Value>
</CostCenter>
</ClientCostCenter>
</Invoicing>
</EGE_Booking>
";
// result will be an iterator over tuples containing the start and end indices for each match in the string
let result = regex.captures_iter(string);
for mat in result {
println!("{:?}", mat);
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Rust, please visit: https://docs.rs/regex/latest/regex/