There is only one way to be pure before God, and that is to be filled with, led by, consumed with the Holy Spirit.
While many will tell you to do this and don't do that, none of these things, which have the appearance of Godliness, are of any value against the sins of the flesh.
It all comes down to abiding in Jesus. Any sexual gratification is giving pleasure to the flesh. Sins come in three forms, these being the lusts of the flesh, the lusts of the eyes, and the pride of life.
If we are filled with the Spirit, then we will not fulfill the lusts of the flesh. If we are consumed with Jesus, which is being consumed by His Spirit, then we will not fulfill the lusts of the eyes. If we abide in Him, which means we remain in His presence, we will not fulfill the pride of life, for true humility comes from knowing God.
The reason that the Law does not bring righteousness is that the Law can only work through the flesh, which is consumed in lusts and sin. The Spirit is not like this, and in truth if we are led by the Spirit, we put to death the deeds of the flesh.
All of this to say that you should not condemn yourself. Rather, seek God's face and His judgment and forgiveness and love.