import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "<(?:Attendance)[^>]+\\sBookingReference\\=\\\"0317000067\\b[^>]*>";
final String string = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
+ "<!--MSW.MAPS.Extractor, Version=10.6.301.17, Culture=neutral, PublicKeyToken=null-->\n"
+ "<!--Started at 2017-03-29 10:35:03Z-->\n"
+ "<HealthRosterExtract>\n"
+ " <HDR FileName=\"TA__MSW_MN1802_000009.DAT\" CreationDate=\"20170329103503\" SystemSourceCode=\"MSW\" TrustIdentifier=\"\" PeriodType=\"M\" ProcessType=\"N\" ExtractType=\"AttendanceAndAbsence\" HistoricPeriods=\"0\" CostCentreSource=\"Duty\" InhibitSubjectiveCodes=\"False\" ExcludeVPD=\"False\" AggregrateTimeAndAttendanceData=\"False\" SequenceNumber=\"9\" PayChannel=\"Generic Bank\" ExtractRunID=\"762\" OrgUnit=\"DL Ward\" ExtractBatch=\"\" IsTestExtract=\"False\" TaxPeriod=\"2\" PeriodValidFrom=\"20170201000000\" PeriodValidTo=\"20170228000000\" /><ATT><Attendance EffectiveDate=\"\" OperationType=\"Add\" StaffNumber=\"87654321\" AssignmentNumber=\"87654321\" Surname=\"Bank\" Forenames=\"Generic\" EarnedDate=\"20170227\" ElementName=\"Band 5 Mon - Fri H\" ElementValueName1=\"Units to Pay\" ElementValueOption1=\"FixedValue\" ElementValueText1=\"Pay Hours\" ElementValueName2=\"Rate of Pay\" ElementValueOption2=\"FixedValue\" ElementValueText2=\"18.32\" ElementValueName3=\"\" ElementValueOption3=\"NotInUse\" ElementValueText3=\"\" ElementValueName4=\"\" ElementValueOption4=\"NotInUse\" ElementValueText4=\"\" ElementValueName5=\"\" ElementValueOption5=\"NotInUse\" ElementValueText5=\"\" ElementValueName6=\"\" ElementValueOption6=\"NotInUse\" ElementValueText6=\"\" ElementValueName7=\"\" ElementValueOption7=\"NotInUse\" ElementValueText7=\"\" ElementValueName8=\"\" ElementValueOption8=\"NotInUse\" ElementValueText8=\"\" CostCentreCode=\"12345\" DutyCostCentreCode=\"12345\" DutyCostCentreName=\"Dom Ward\" DutyCostCentreExternalRef=\"\" PostingCostCentreCode=\"\" PostingCostCentreName=\"\" PostingCostCentreExternalRef=\"\" PayHours=\"7.50\" WorkHours=\"7.50\" Occurances=\"1.00\" NegotiatedRate=\"0.00\" SubjectiveCode=\"\" DateWorked=\"20170227\" GradeExternalReference=\"Band5RN\" UnitExternalReference=\"\" AllowanceUnits=\"0\" ExternalAbsenceType=\"\" ExternalAbsenceCode=\"\" ExternalAbsenceReference=\"\" DutyAssignmentStartDateTime=\"20170227070000\" DutyAssignmentEndDateTime=\"20170227150000\" BreakdownStartDateTime=\"20170227070000\" BreakdownEndDateTime=\"20170227150000\" UnavailabilityStartDateTime=\"\" UnavailabilityEndDateTime=\"\" UnavailabilityHasOverlappingCancelledDuties=\"False\" DutyCancelReason=\"\" BookingReference=\"0317000043\" BookingMethod=\"ManualManagerAssignment\" /><Attendance EffectiveDate=\"\" OperationType=\"Add\" StaffNumber=\"76543211\" AssignmentNumber=\"76543211\" Surname=\"Bank\" Forenames=\"Daily\" EarnedDate=\"20170228\" ElementName=\"Band 5 Mon - Fri D\" ElementValueName1=\"Units to Pay\" ElementValueOption1=\"FixedValue\" ElementValueText1=\"Occurrence\" ElementValueName2=\"Rate of Pay\" ElementValueOption2=\"FixedValue\" ElementValueText2=\"200\" ElementValueName3=\"\" ElementValueOption3=\"NotInUse\" ElementValueText3=\"\" ElementValueName4=\"\" ElementValueOption4=\"NotInUse\" ElementValueText4=\"\" ElementValueName5=\"\" ElementValueOption5=\"NotInUse\" ElementValueText5=\"\" ElementValueName6=\"\" ElementValueOption6=\"NotInUse\" ElementValueText6=\"\" ElementValueName7=\"\" ElementValueOption7=\"NotInUse\" ElementValueText7=\"\" ElementValueName8=\"\" ElementValueOption8=\"NotInUse\" ElementValueText8=\"\" CostCentreCode=\"12345\" DutyCostCentreCode=\"12345\" DutyCostCentreName=\"Dom Ward\" DutyCostCentreExternalRef=\"\" PostingCostCentreCode=\"\" PostingCostCentreName=\"\" PostingCostCentreExternalRef=\"\" PayHours=\"7.50\" WorkHours=\"7.50\" Occurances=\"1.00\" NegotiatedRate=\"0.00\" SubjectiveCode=\"\" DateWorked=\"20170228\" GradeExternalReference=\"Band5RN\" UnitExternalReference=\"\" AllowanceUnits=\"0\" ExternalAbsenceType=\"\" ExternalAbsenceCode=\"\" ExternalAbsenceReference=\"\" DutyAssignmentStartDateTime=\"20170228070000\" DutyAssignmentEndDateTime=\"20170228150000\" BreakdownStartDateTime=\"20170228070000\" BreakdownEndDateTime=\"20170228150000\" UnavailabilityStartDateTime=\"\" UnavailabilityEndDateTime=\"\" UnavailabilityHasOverlappingCancelledDuties=\"False\" DutyCancelReason=\"\" BookingReference=\"0317000045\" BookingMethod=\"ManualManagerAssignment\" /> \n\n"
+ "<Attendance EffectiveDate=\"\" OperationType=\"Add\" StaffNumber=\"76543211\" AssignmentNumber=\"76543211\" Surname=\"Bank\" Forenames=\"Daily\" EarnedDate=\"20170228\" ElementName=\"Band 5 Mon - Fri D\" ElementValueName1=\"Units to Pay\" ElementValueOption1=\"FixedValue\" ElementValueText1=\"Occurrence\" ElementValueName2=\"Rate of Pay\" ElementValueOption2=\"FixedValue\" ElementValueText2=\"200\" ElementValueName3=\"\" ElementValueOption3=\"NotInUse\" ElementValueText3=\"\" ElementValueName4=\"\" ElementValueOption4=\"NotInUse\" ElementValueText4=\"\" ElementValueName5=\"\" ElementValueOption5=\"NotInUse\" ElementValueText5=\"\" ElementValueName6=\"\" ElementValueOption6=\"NotInUse\" ElementValueText6=\"\" ElementValueName7=\"\" ElementValueOption7=\"NotInUse\" ElementValueText7=\"\" ElementValueName8=\"\" ElementValueOption8=\"NotInUse\" ElementValueText8=\"\" CostCentreCode=\"12345\" DutyCostCentreCode=\"12345\" DutyCostCentreName=\"Dom Ward\" DutyCostCentreExternalRef=\"\" PostingCostCentreCode=\"\" PostingCostCentreName=\"\" PostingCostCentreExternalRef=\"\" PayHours=\"7.50\" WorkHours=\"7.50\" Occurances=\"1.00\" NegotiatedRate=\"0.00\" SubjectiveCode=\"\" DateWorked=\"20170228\" GradeExternalReference=\"Band5RN\" UnitExternalReference=\"\" AllowanceUnits=\"0\" ExternalAbsenceType=\"\" ExternalAbsenceCode=\"\" ExternalAbsenceReference=\"\" DutyAssignmentStartDateTime=\"20170228070000\" DutyAssignmentEndDateTime=\"20170228150000\" BreakdownStartDateTime=\"20170228070000\" BreakdownEndDateTime=\"20170228150000\" UnavailabilityStartDateTime=\"\" UnavailabilityEndDateTime=\"\" UnavailabilityHasOverlappingCancelledDuties=\"False\" DutyCancelReason=\"\" BookingReference=\"0317000067\" BookingMethod=\"ManualManagerAssignment\" /></ATT> <FTR RecordCount=\"2\" PayHoursTotal=\"15.00\" StaffNumbersCount=\"2\" AssignmentNumbersCount=\"2\" BookingReferencesCount=\"2\" HashTotal=\"0\" /></HealthRosterExtract><!--Finished at 2017-03-29 10:35:04Z-->";
final Pattern pattern = Pattern.compile(regex);
final Matcher matcher = pattern.matcher(string);
if (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
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 Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html