Tell me, in the writing of the regular season. It is necessary to remove any number of zeros before the first unit (leave one) and remove all 0 and 1 before a . Latex expression - 01 ^ {01a} There is such a sketch https://regex101.com/r/yE5sJl/2 , but it removes { and latex breaks.
1 answer
Use
s.replace(/^0+|({)[01]+/g, '$1') See the demo expressions.
Details
^0+- one or more zeros at the beginning of a line|- or({)- Group (disguise) №1: symbol{[01]+- 0 or 1, one or more repetitions.
Matches are replaced by the value of the first group, i.e. either by an empty string (if the first alternative matches) or by the { symbol (thus, the bracket is not removed from the string).
JS-demo:
var strs = ['01^{0001a}','01^{a}','1^{01a}','01^{01a}']; for (var s of strs) { console.log(s, '=>', s.replace(/^0+|({)[01]+/g, '$1')); } If it is very, very necessary that after {01010 be a , add a forward lookup block:
/^0+|({)[01]+(?=a)/g ^^^^^ See another demo .
|
^[0]+|[^^{]+[01]+- MrFylypenko^[0]*|(?!1\^{)[01]*|(?!a})$- MrFylypenko1^{a}why delete something, if you can just replace it with this line? or write more examples - teran