According to http://www.regexplanet.com/advanced/java/index.html, my regex
\\uline\{[a-zA-Z\d]+\}|\\text(super|sub)script\{[0-9]+.[0-9]+\}
should work fine to detect e.g. 1) \textsuperscript{1.1} and 2) \uline{name}
Furthermore, replaceFirst works as expected: 12345\textsuperscript{1.1}6789 goes to 123456789
I doubled backslashes and added the regex to my Kotlin code (in IntelliJ Idea):
var stylingRegex = "\\\\uline\\{[a-zA-Z\\d]+\\}|\\\\text(super|sub)script \\{[0-9]+.[0-9]+\\}"
var testString = "12345\\uline{james}678"
testString = testString.replaceFirst(Pattern.quote(stylingRegex), "")
println("testString: " + testString)
However, what's printed is the initialized string without any modification.
Pattern.quote(), usetestString = testString.replaceFirst(stylingRegex.toRegex(), "")