01FILENO00012 CRD 20250212015407CRD TEXTFIL1 DAT INTERNALD & NUMBER1 00320250211 |
This is one record/line in my text file. I am trying to verify if the format of file is correct.
Now, the record should have exact number of whitespaces and some words never change.
Now, “01FILENO000012”, “CRD” , “TEXTFILE1” are static and never change … so i want to match these exactly in brackets?
/ System.out.println("Length of line is: " + line.length() + " " + line);
if (line.startsWith("01") && line.trim().matches(
"(01FILENO00012)\s+(CRD)\s{8}[0-9]{14}(CRD)\s+(TEXTFIL1)\s+(DAT)\s+(INTERNALD)\s+(&)\s+(NUMBER1)\s{14}[0-9]{11}\s{44}[|]")) {
{
System.out.println("This is header record: " + line + " and its has correct format");
}
Please help me write correct Java regex so that i can automate file format verification?
Source: Read More