This is way how to detect the parts with different character properties in selection, probably you can remake it to Function and use oFound instead oSel. But the conditions if ParaName= AND Style<> AND Props= then
will be more complicated.
Select some text that has the different formatted parts (bold, superscript, underline etc.) and run macro
Sub differentCharProperties 'show the parts that has different character properties in selection
dim oDoc as object, oSel as object, oEnum as object, o as object, oEnum2 as object, o2 as object
oDoc=ThisComponent
oSel=oDoc.CurrentController.Selection.getByIndex(0)
oEnum=oSel.createEnumeration
do while oEnum.hasMoreElements
o=oEnum.nextElement
oEnum2=o.createEnumeration
do while oEnum2.hasMoreElements
o2=oEnum2.nextElement
msgbox o2.string 'show part of string with different properties than other parts
'xray o2
loop
loop
End Sub
There are the properties CharEscapement and CharEscapementHeight (or maybe you also use CharAutoEscapement) for Super/Sub-script → CharEscapement has plus values for Superscript (for example 30), and minus values for Subscript (-30).
Be carefull when make the replace definitions, longer ones have to be before shorter. In your example SourceWords() = Array("Gb","G","G#", ...)
→ there will never be found G# because single expression G is before longer expression G# → so it will replace all G that means also all G from G#.