import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "calypso:calypsoObject.{10,150}xsi:type=\"calypso:(\\w{2,50})";
final String string = "<calypso:calypsoDocument xmlns:datauploader=\"http://www.calypso.com/datauploader\" xmlns:ftp=\"http://www.calypso.com/ftp\" xmlns:liquidityrule=\"http://www.calypso.com/liquidityrule\" xmlns:bloomberg=\"http://www.calypso.com/bloomberg\" xmlns:liquiditycriteria=\"http://www.calypso.com/liquiditycriteria\" xmlns:pricingscript=\"http://www.calypso.com/pricingscript\" xmlns:am=\"http://www.calypso.com/am\" xmlns:liquidityposition=\"http://www.calypso.com/liquidityposition\" xmlns:scriptableOTC=\"http://www.calypso.com/scriptableOTC\" xmlns:pricingsheet=\"http://www.calypso.com/pricingsheet\" xmlns:matching=\"http://www.calypso.com/matching\" xmlns:scheduler=\"http://www.calypso.com/scheduler\" xmlns:ns20=\"http://www.calypso.com/HedgeAccounting\" xmlns:liquidityreporting=\"http://www.calypso.com/liquidityreporting\" xmlns:taskstation=\"http://www.calypso.com/taskstation\" xmlns:kpiservice=\"http://www.calypso.com/kpiservice\" xmlns:liquiditycore=\"http://www.calypso.com/liquiditycore\" xmlns:calypso=\"http://www.calypso.com/xml\" xmlns:assumption=\"http://www.calypso.com/assumption\" xmlns:liquidityclassification=\"http://www.calypso.com/liquidityclassification\" xmlns:collateral=\"http://www.calypso.com/collateral\" xmlns:calculationserver=\"http://www.calypso.com/calculationserver\" xmlns:bondexoticnote=\"http://www.calypso.com/bondexoticnote\"><calypso:calypsoObject xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"calypso:FutureCommodity\" version=\"14-0\" action=\"SAVE\"><calypso:identification><calypso:versionedIdentifier version=\"0\" code=\"21866845\" codifier=\"CPSLIVE\"/></calypso:identification><calypso:definition><calypso:contract><calypso:type>com.calypso.tk.product.FutureContract</calypso:type><calypso:separator>#</calypso:separator><calypso:identifier code=\"USD#LME#LMEZinc\" codifier=\"convention\"/><calypso:calypsoBusinessKey><calypso:propertyName>currency</calypso:propertyName><calypso:propertyValue>USD</calypso:propertyValue></calypso:calypsoBusinessKey><calypso:calypsoBusinessKey><calypso:propertyName>exchange</calypso:propertyName><calypso:propertyValue>LME</calypso:propertyValue></calypso:calypsoBusinessKey><calypso:calypsoBusinessKey><calypso:propertyName>name</calypso:propertyName><calypso:propertyValue>LMEZinc</calypso:propertyValue></calypso:calypsoBusinessKey></calypso:contract><calypso:expirationDate>2023-10-30Z</calypso:expirationDate><calypso:firstDeliveryDate>2023-10-30Z</calypso:firstDeliveryDate><calypso:firstNotificationDate>2023-10-30Z</calypso:firstNotificationDate><calypso:lastDeliveryDate>2023-10-30Z</calypso:lastDeliveryDate><calypso:lastNotificationDate>2023-10-30Z</calypso:lastNotificationDate><calypso:tradingEndDate>2023-10-30Z</calypso:tradingEndDate><calypso:tradingStartDate>2023-10-30Z</calypso:tradingStartDate><calypso:ccpDate>2023-10-30Z</calypso:ccpDate></calypso:definition></calypso:calypsoObject></calypso:calypsoDocument>";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
while (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