Hi all,
I am writing the documentation for a package of mine, and in a doctest I have this output:
11-element Vector{ComplexF64}:
0.0 + 0.0im
-1.617576049847552e-6 + 6.617439891157473e-23im
-2.216802827443102e-6 - 2.602082008249062e-18im
-2.1754485086580383e-5 + 5.293471330973909e-22im
4.696594721193055e-5 + 6.511993073259912e-21im
-6.763856924121541e-5 + 3.4410971976147374e-21im
-3.686889866871368e-5 - 3.599741391814458e-21im
2.176614750375809e-5 + 2.6487551060169705e-22im
-6.419493464380101e-5 - 2.8434333556510326e-25im
-0.00010698407746021099 + 6.775843525379591e-21im
4.065995056214414e-5 + 6.776282561183226e-21im
a pretty standard array of complex numbers.
Now, I don’t care that much about the actual numbers, I just want to show a list of eleven complex numbers, so I assign the following substitution rule to the filter keyword of the doctest, :
r"^(\s+)?[-+]?([0-9]*[.])?[0-9]+([eE][-+]?\d+)? [-+] [-+]?([0-9]*[.])?[0-9]+([eE][-+]?\d+)?im"m => "### + ###im"
and set the expected output to
11-element Vector{ComplexF64}:
### + ###im
### + ###im
### + ###im
### + ###im
### + ###im
### + ###im
### + ###im
### + ###im
### + ###im
### + ###im
### + ###im
As you can see, I have to deal not only with the actual floating-point numbers, but also to the variable white space at the beginning of each line.
That’s why I composed the regex with this structure in mind: “(variable amount of whitespace at beginning of line) (floating-point number) [-+] (floating-point number)im”. I put the m flag at the end of the raw string so that the ^ matches the start of each line instead of the start of the whole string only (it shouldn’t matter for the doctest, since, I think, each line is matched separately).
This works as expected in the REPL:
julia> str = """11-element Vector{ComplexF64}:
0.0 + 0.0im
-1.617576049847552e-6 + 6.617439891157473e-23im
-2.216802827443102e-6 - 2.602082008249062e-18im
-2.1754485086580383e-5 + 5.293471330973909e-22im
4.696594721193055e-5 + 6.511993073259912e-21im
-6.763856924121541e-5 + 3.4410971976147374e-21im
-3.686889866871368e-5 - 3.599741391814458e-21im
2.176614750375809e-5 + 2.6487551060169705e-22im
-6.419493464380101e-5 - 2.8434333556510326e-25im
-0.00010698407746021099 + 6.775843525379591e-21im
4.065995056214414e-5 + 6.776282561183226e-21im""";
julia> replace(str, r"^(\s+)?[-+]?([0-9]*[.])?[0-9]+([eE][-+]?\d+)? [-+] [-+]?([0-9]*[.])?[0-9]+([eE][-+]?\d+)?im"m => "### + ###im") |> print
11-element Vector{ComplexF64}:
### + ###im
### + ###im
### + ###im
### + ###im
### + ###im
### + ###im
### + ###im
### + ###im
### + ###im
### + ###im
### + ###im
and yet the debug messages of Documenter show this:
Evaluated output (filtered):
11-element Vector{ComplexF64}:
0.0 + 0.0im
-1.617576049847552e-6 + 6.617439891157473e-23im
-2.216802827443102e-6 - 2.602082008249062e-18im
-2.1754485086580383e-5 + 5.293471330973909e-22im
4.696594721193055e-5 + 6.511993073259912e-21im
-6.763856924121541e-5 + 3.4410971976147374e-21im
-3.686889866871368e-5 - 3.599741391814458e-21im
2.176614750375809e-5 + 2.6487551060169705e-22im
-6.419493464380101e-5 - 2.8434333556510326e-25im
-0.00010698407746021099 + 6.775843525379591e-21im
4.065995056214414e-5 + 6.776282561183226e-21im
meaning that the regex filer didn’t work as expected.
I’m at a loss here, can some please help me and show me what I’m doing wrong?