Question: I have a text file with many lines like this:

```
IMG_0106.JPG    y:\2004_05_23_bern basel\       2004_05_23
IMG_0107.JPG    y:\2004_05_23_dortmund\         2004_05_23
IMG_0108.JPG    y:\2004_05_25_paris\            2004_05_24
IMG_0110.JPG    y:\2004_05_25_paris\            2004_05_25

```

I want to check if there are double dates in the same line
and where not.

Line 1,2,4 have a date match.  

Line 3 doesn't have a date match (2004\_05\_25 != 2004\_05\_24) 

I know how to find double lines but I don't know how to find doubles in the same line in this case.  

Can someone please help me?

Answer: 
You need to anchor the lookbehind assertion to the start of the string, or it will match a substring:

```
Pattern matcher = Pattern.compile("(\\d{6,12})\\.(\\d{0,6})(?<=^.{13})");

```

Or use a lookahead assertion instead (easier to understand, IMO):

```
Pattern matcher = Pattern.compile("(?=.{13}$)(\\d{6,12})\\.(\\d{0,6})");

```
You need to use anchor to match at the beginning of the string:

```
"(\\d{6,12})\\.(\\d{0,6})(?<=^.{13})"

```