I have a title in the following format - test ^TM^ title test. I want to convert this text in such a way that the word enclosed between '^' as superscript without changing its position, as shown below.
testTMtitle test
Please help me.
I have a title in the following format - test ^TM^ title test. I want to convert this text in such a way that the word enclosed between '^' as superscript without changing its position, as shown below.
testTMtitle test
Please help me.
A regex can do this for you, see the example below.
const
  input = 'test ^TM^ title test',
  // This regex will match any text between two "^" characters. The text
  // between the "^" will be placed inside a capture group.
  regex = /\^(.*?)\^/g,  
  // This replaces the match with the text from the capture group, wrapped in a sup tag.
  htmlString = input.replace(regex, `<sup>$1</sup>`);
  
console.log(htmlString);
document.getElementById('output').innerHTML = htmlString;
<div id="output"></div>
Using javascript:
text = "test ^TM^ title test";
text.replace(/\^(.+?)\^/g,'$1'.sup());
I thinks you need to open your files in any HTML or PHP editor and use find and replace option. For example: find ^TM^ Replace with: TM
string = "hello^TM^ hi";
isOdd = true;
newString  = "";
for(i=0; i<string.length; i++){
    if(string[i] == '^'){
        if(isOdd){
            newString += "<sup>";
        } else {
            newString += "</sup>";
        }
        isOdd = !isOdd;
    } else{
        newString += string[i];
    }
}
//newString will have "hello<sup>TM</sup> hi"