fabien van mook

all packages "fvm-*"

package "fvm-miscellaneous"

function file "tagexponents.m"

Function r = tagexponents(s,tag1,tag2)

"tags" the exponents in string s and returns the 
result in string r.

The function looks for ordinary computer representations
of real numbers with an exponent by "e", e.g. 1e3 
for one thousand. 

More precisely in a regex notation, this is the pattern
of the number expression which is searched for:
  [-+]{0,1}[0-9]{1,}(.[0-9]{1,}){0,1}[eEdD][-+]{0,1}[0-9]{1,}
So:
-- the number expression always contains an "e",
   "E", "d" or "D" between the mantissa and 
   exponent;
-- the mantissa contains at least one digit;
-- the mantissa may or may not contain a decimal
   dot; if it does, there are always digits before
   and after the dot;
-- the exponent contains at least one digit.

There may be zero, one or more such number 
expressions in input string s. There may also
be other words (letters etc.) in string s. 
Multiple number expressions must be separated 
from each other and from other words by: spaces,
end-of-line characters \n and \r, tab characters \t,
commas, semicolons, slashes / and \, and brackets 
( ) [ ] { } < >.

When an number expression is found, the tags 
tag1 and tag2 are inserted. Moreover, plus signs 
(of the number and of the exponent) and 
non-significant (leading) zeros within exponents 
are removed.

E.g. 
 tagexponents("1.23e+04 5.6e-07 1e8 2e+0","<exp>","</exp>")
returns:
 "1.23<exp>4</exp> 5.6<exp>-7</exp> 1<exp>8</exp> 2<exp>0</exp>".

And 
 tagexponents("array = [+1.23e+005,-23.45e-098,tree3]","<exp>","</exp>")
returns:
 "array = [1.23<exp>5</exp>,-23.45<exp>-98</exp>,tree3]".

Issue e.g. 
 tagexponents(s,"e","")
to get only the removal of plus signs and non-significant
zeros within exponents.


(c) 2026 fabien van mook

2026.08.20 release of this file within package "fvm-miscellaneous" under GNU GPLv3+