Joshua bought a box of pens. 1/8 of the pens were black, 1/4 were blue and 2/5 of the remaining were red. If there were 18 red pens, how many did she buy?

If 2/5 of the remaining pens were red, there were 5/5-2/5 = 3/5 that were not red.

The number of pens that were not red is 3/5*18 = <<3/5*18=10.8>>10.8 pens
The total number of pens that were not red or black are 10.8+18 = <<10.8+18=28.8>>28.8 pens
The box of pens that Joshua bought had 28.8/5 = <<28.8/5=5.76>>5.76*5 = <<5.76*5=28.8>>28.8 pens. Answer: \boxed{28}.