Racist and homophobic text messages sent by and to a former San Francisco police officer have been released amid a growing scandal over such messages among law enforcement.

Jason Lai has resigned from the San Francisco Police Department following a 2015 investigation that first looked into sexual-assault allegations, police said.

CNN recently obtained numerous texts to and from Lai that came to light during that investigation, including one in which Lai purportedly wrote, “Indian ppl are disgusting,” and another in which he allegedly used two racial slurs, saying: “I hate that [Hispanic] but I think the [African American] is worse.”

Lai, a six-year veteran on the force, appeared to have made derogatory comments about numerous ethnic groups as well as gay police officers, according to CNN. “Passive aggressive 528,” he reportedly wrote, using the code for a fire call to insinuate that gay officers are “flames or flaming,” a source told the network.

He purportedly talked about an incident when a “bunch of hock (sic) gwais shooting each other.” The Cantonese phrase “hak gwai” is a term for African Americans.

“Sprained my ankle over these barbarians,” Lai wrote, according to CNN, adding that one suspect was rushed to a hospital with a gunshot wound. “Too bad none of them died. … One less to worry about.”

The messages were discovered during a sexual-assault probe last year amid allegations from a woman who claimed she was on a date with Lai, who was off-duty, when he raped her, according to the Associated Press.

Prosecutors said they did not have enough evidence to charge Lai with sexual assault. However, police said, he has since been charged with unlawful access and/or use of criminal and motor vehicle databases.

Lai’s attorney, Don Nobles, told CNN this week that the text messages were taken from Lai’s personal cellphone and were “not reflective of who he is” or his abilities as a police officer.

“It’s hard to say any of those things in context,” he said, “but there is context to it.”

Police said that at least four officers were involved in the recent texting scandal. Three are no longer with the department, police said, and the fourth faces disciplinary action.

“As has been clearly stated but cannot be overstated enough, there is no room in this department for anyone who holds these types of hateful and discriminatory views,” Police Chief Greg Suhr said in a statement. “Any officer who engages in such reprehensible racist and homophobic remarks will be held accountable and swiftly dealt with. These views are clearly incompatible with the character required of being a police officer.

“We will not allow officers capable of such conduct to sully the good name of the San Francisco Police Department and what we stand for.”

This is at least the second time the San Francisco Police Department has been at the center of public embarrassment over racist text messages.

The SFPD’s first texting scandal occurred last year when a federal prosecutor filed court papers detailing racist and homophobic texts made by former SFPD Sgt. Ian Furminger, one of three officers convicted of stealing money and drugs from the residents of low-rent Tenderloin hotels. … Fourteen officers, including a captain, were implicated in sending or receiving such texts.

The latest cache of texts was provided to CNN by San Francisco Public Defender Jeff Adachi, whose office “is representing a defendant in a case in which Lai was involved,” the network reported. “Evidence of biased attitudes could be used to undermine the officer’s credibility and result in cases being dismissed.”

Adachi told CNN that he couldn’t help but wonder what other officers on the force might be texting about, noting that Lai’s messages — as well as those in the earlier SFPD case — were discovered by accident.

“What are the chances of two officers being arrested … and there’s racists texts on [their phones]?” Adachi said. “I don’t know what the odds would be in Vegas.”

Police Sgt. Yulanda Williams, president of an African American police officers’ association called Officers for Justice, told the San Francisco Chronicle last month that she was upset to hear about yet another racist scandal.

“Clearly, there seems to be some underlying issues that have still not been addressed,” Williams told the newspaper. “I would never assume that every member of the San Francisco Police Department is involved because that would be the furthest thing from the truth. But for those of us who do not engage in this type of activity, it’s extremely hurtful and it’s extremely embarrassing. And it’s got to end.”

Suhr, the police chief, told CNN that he takes “swift and severe” action when he learns of such behavior.

In the recently uncovered texts, the network reported, Lai “makes a disparaging joke about President Obama and says he hates basketball player LeBron James,” using a shortened version of the n-word to dismiss the latter.

Nobles, Lai’s attorney, told CNN that the former officer “was well-liked and well loved on his beat,” adding: “There is no evidence he carried out any of those sentiments as an officer.”

This story has been updated.