This question is related to How to convert numbers after caret to superscript with jquery where I got a very good answer.
Problem now, I need to extend the recent script | jsfiddle so that it takes successive numbers into account.
The recent script takes a string, and checks it for carets. Then:
- If there is no bracket behind the caret, only superscript the next character.
x^2
becomesx<sup>2</sup>
- If there is an opening bracket, superscript until the closing bracket.
x^(2y+1)
becomesx<sup>2y+1</sup>
However, I need to extend n°1 as there might be a number holding several digits or even variables.
So we need a new n°1:
- If there is no bracket behind the caret, superscript all successive characters as long as they are numbers or characters. So that
x^12a
becomesx<sup>12a</sup>
I tried to implement it, including a variable afternext = input[ (i+1) ])
and checking this char by if(afternext.match(/^[0-9a-zA-Z]+$/)) { ... }
storing it, but I failed :(
So if anyone feels fit enough today, I'd be happy to see your solution for that.
Thank you.