The editor of the Times has voiced regret over a reporter's use of email hacking to identify an anonymous police blogger.

In his second appearance before the Leveson Inquiry into press ethics, editor James Harding also revealed that the paper's chief lawyer knew that story information was obtained by illegitimate means although this was not made clear at the high court.

Harding told the inquiry that he would have told reporter Patrick Foster to stop his attempts to identify an anonymous police blogger if he had known that Foster had hacked private emails to get the information.

A police investigation was launched into email hacking at the Times after Harding gave evidence at his first appearance at the inquiry in January.

He revealed that Foster had been given a formal warning for professional misconduct after gaining unauthorised access to Lancashire detective Richard Horton's email account.

The paper later named Horton as the author of the Nightjack blog in 2009.

At his lates appearance at the inquiry Harding said: "I sorely regret the intrusion into Richard Horton's email account by a journalist in our newsroom. On behalf of the newspaper, I apologise."

The high court ruled against granting Horton anonymity as Foster was able to prove that he had gained proof of his identity to run the story through sufficiently legitimate means.

A series of Foster's emails read at the inquiry revealed that Foster contacted home news editor Martin Barrow, asking to talk about the story "away from the desk", apparently after the hacking had taken place.

He also spoke to Times legal manager Alastair Brett who Harding said "tore a strip off" Foster and told him he had to back up the story legitimately. Foster later did so using a publically available Facebook page.

"To be absolutely clear, if [Foster] had come to me and said he had done this I would have taken the disciplinary action that we did take as I would've told him to abandon the story, so that it wouldn't open the newspaper up to the [hacking] charge," Harding told the inquiry.

He stressed that the story had a strong public interest, but that there was not sufficient interest for hacking to be warranted.

Robert Jay QC questioned the validity of Foster's "legitimate" research into an identity he already knew.

"It's like working from the inside of a maze out, rather than from the inside in," he said.

Jay read material placed before the high court by the Times that repeated that legitimate reporting work was used to identify Nightjack.