A homeless man was busted in connection with an attempted rape after cops spotted him urinating on a car in Chinatown — and recognized him from having seen him drunk and clad in a distinctive Batman jacket the week before.

Rubicel Sanchez was relieving himself against a vehicle on East Broadway near Market Street at around 9:15 p.m. when Officers Daniel Roth and Frank Faber spotted him.

Twenty hours earlier, at around 1 a.m., Sanchez wore a Batman jacket when he tried to rape a 62-year-old woman in the rear lobby of her apartment building, police said.

Sanchez had been wearing the same jacket a week earlier, when Roth and Faber tried to coax him into an ambulance after finding him drunk near Madison and Market streets, but Sanchez slipped away.

So when the officers later saw surveillance-camera images of the attempted rape, with the attacker wearing a Batman jacket, they knew who to look for.

When they found him Friday night, Faber and Roth moved in and cuffed him.

By the time Faber and Roth found him, Sanchez had ditched the Batman jacket. He was charged with attempted rape, burglary and sex abuse.

Police sources say Sanchez was picked out of a lineup in the attempted rape.