User:Xenwolf/SandBox: Difference between revisions

Xenwolf (talk | contribs)
Testing factor notation: added input and legend
Xenwolf (talk | contribs)
Testing factor notation: this is of course an important point
Line 126: Line 126:
== Testing factor notation ==
== Testing factor notation ==


Input: <code>2^-4 * 3^4 * 5^-1</code>
This solution requires valid (and sensible) input, there is no intelligence on board that would be able to detect zero divisions like <code>0^-1</code>.


Code: <code><nowiki>{{#replace:{{#regex: 2^-4 * 3^4 * 5^-1|/(\d+)\s*\^\s*(-?\d+)(\s*\*\s*)?/|\1<sup>\2</sup> \3&amp;nbsp;}}|*|⋅}}</nowiki></code>
=== 1st version with mandatory exponents ===


Output: {{#replace:{{#regex: 2^-4 * 3^4 * 5^-1|/(\d+)\s*\^\s*(-?\d+)(\s*\*\s*)?/|\1<sup>\2</sup> \3&nbsp;}}|*|⋅}}
: Input: <code>2^-4 * 3^4 * 5^-1</code>
: Code: <code><nowiki>{{#replace:{{#regex: 2^-4 * 3^4 * 5^-1|/(\d+)\s*\^\s*(-?\d+)(\s*\*\s*)?/|\1<sup>\2</sup> \3&amp;nbsp;}}|*|⋅}}</nowiki></code>
: Output: {{#replace:{{#regex: 2^-4 * 3^4 * 5^-1|/(\d+)\s*\^\s*(-?\d+)(\s*\*\s*)?/|\1<sup>\2</sup> \3&nbsp;}}|*|⋅}}
 
=== 2nd version with optional exponents ===
 
: Input: <code>2^2 * 5 * 11^-1</code>
: Code: <code><nowiki>{{#replace:{{#regex: 2^2 * 5 * 11^-1|/(\d+)(?:\s*\^\s*(-?\d+))?(\s*\*\s*)?/|\1<sup>\2</sup> \3&amp;nbsp;}}|*|⋅}}</nowiki></code>
: Output:  {{#replace:{{#regex: 2^2 * 5 * 11^-1|/(\d+)(?:\s*\^\s*(-?\d+))?(\s*\*\s*)?/|\1<sup>\2</sup> \3&nbsp;}}|*|⋅}}