import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^(((([A-Z]+-)?((\\d{2})([A-Z]{3})(\\d{2}))?([A-Z]{3})?( )?((.[0-9A-Z]{3})|([0-9A-Z]{2}))( )([X][\\/])?((E\\/)|(B\\/)|(T\\/)|(L\\/))*(([A-Z][\\/-])?[A-Z]{3})?(?!\\d{1,3}[A-Z\\s])( )?(((E\\/XXX)?|([Q]{1}(( )?([A-Z]{3})([A-Z]{3}))?(\\d+M)?(\\d{1,6}(\\.\\d{1,4})?))?|(M( )?([A-Z]{6})?( )?(\\d{1,6}(\\.\\d{1,4})?)?)?|([R]{1}(\\d+M)?(\\d{1,6}(\\.\\d{1,4})?))?|(([0-9])*S(\\d+M)?(\\d{1,6}(\\.\\d{1,4})?))?|(M?\\/(IT))|(M?\\/(BT))|(\\/\\/([A-Z]{3})))( )?)*(\\d+M( )?)?((?![0-9][A-Z])\\d{1,6}(\\.\\d{1,4})?( )?)?((?<=[0-9])((?![A-Z][A-Z0-9]( )([A-Z]\\/)?[A-Z]{3}|NUC|END|[A-Z]{3}( )[0-9])|(?=[A-Z][A-Z0-9]( )NUC))[A-Z][A-Z0-9\\/]{0,8})?(( )?(([Q]{1}(\\d+M)?(\\d{1,6}(\\.\\d{1,4})?))|(P R\\/([A-Z]{3})(\\/)?([A-Z]{3})?( )?(\\d+M)?(\\d{1,6}(\\.\\d{1,4})?))|(P( )([A-Z]{6})( )?([A-Z]{6})?( )?(\\d+M)?(\\d{1,6}(\\.\\d{1,4})?))|(M( )?([A-Z]{6})?( )?(\\d{1,6}(\\.\\d{1,4})?)?)|(H( )([A-Z]{6})( )?(\\d{1,6}(\\.\\d{1,4})?))|(U( )(( )?([A-Z]{6}))+( )?(\\d{1,6}(\\.\\d{1,4})?))|(C\\/([A-Z]{3})(( )?[A-Z]{6})*( )?(\\d{1,6}(\\.\\d{1,4})?))|(D( )((([A-Z])+\\/)?([A-Z]{6})( )?((M)|(\\d+M)|( )|(\\d{1,6}(\\.\\d{1,4})?))( )?)+)|(\\/-([A-Z]{3}))|(\\/\\/([A-Z]{3})))?( )?)*)+)+)( )?((( )?([A-Z]{3})( )?(\\d{1,6}(\\.\\d{1,4})?))( )?(END)|(END))( )?(ROE( )?\\d+(\\.\\d+)?)?(.*)?$";
final String string = "SIN UB X/RGN101.29ESGR UB NYT110.00YOW UB RGN110.00YOW RGN UB SIN 101";
final Pattern pattern = Pattern.compile(regex);
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