Find text with both formatting and non-formatting to replace

With the above screenshot, I need to remove the space before superscript text. I'm a beginner in coding such, could someone suggest a code to replace?

With the above screenshot, I need to remove the space before superscript text. I'm a beginner in coding such, could someone suggest a code to replace?
Hi,
Try the following code
app.findGrepPreferences = null
app.findGrepPreferences.appliedCharacterStyle = "superscript"
var a = app.documents[0].findGrep()
while(b = a.pop())
{
var idx = b.index
var con = b.parentStory.insertionPoints.itemByRange(idx - 1,idx).contents
if(con == " ")
b.parentStory.insertionPoints.itemByRange(idx - 1,idx).contents = ""
}
app.findGrepPreferences = NothingEnum.nothing
Edit :- Incorporated the suggestion made by Peter Kahrel in the comment below, we can also change the algorithm as suggested in that post. However the code in this post will also work fine
-Manan
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.