angelcervera
angelcervera

Reputation: 4177

Regex to test md5sum file format

I need test correct format of md5sum file. The format is 32 hexadecimal characters, two spaces and after this, any string of characters. http://en.wikipedia.org/wiki/Md5sum

@Test
public void testMD5() {
    String pattern = "^[0-9abcdef]{32} {2}[\\w]*";
    Assert.assertTrue( Pattern.compile( pattern ).matcher("18742594636e452218b9b3bca10c07f2  dashboard.xml").matches() );
    Assert.assertFalse( Pattern.compile( pattern ).matcher("18742594636e452218b9b3bca10c07f2 dashboard.xml").matches() );
}

Upvotes: 0

Views: 139

Answers (1)

Sabuj Hassan
Sabuj Hassan

Reputation: 39365

Use .* instead of [\\w]*

String pattern = "^[0-9a-f]{32}[ ]{2}.*$";
                                     ^---two spaces and after this, any string of characters

Upvotes: 1

Related Questions