diff --git a/README.md b/README.md index 37bad58..c4c0baf 100644 --- a/README.md +++ b/README.md @@ -365,8 +365,8 @@ import re * **Argument `'flags=re.IGNORECASE'` can be used with all functions.** * **Argument `'flags=re.MULTILINE'` makes `'^'` and `'$'` match the start/end of each line.** * **Argument `'flags=re.DOTALL'` makes dot also accept the `'\n'`.** -* **Use `r'\1'` or `'\\1'` for backreference.** -* **Add `'?'` after an operator to make it non-greedy.** +* **Use `r'\1'` or `'\\1'` for backreference (`'\1'` returns a character with octal code 1).** +* **Add `'?'` after `'*'` and `'+'` to make them non-greedy.** ### Match Object ```python @@ -380,7 +380,7 @@ import re ### Special Sequences * **By default, decimal characters, alphanumerics and whitespaces from all alphabets are matched unless `'flags=re.ASCII'` argument is used.** * **As shown below, it restricts special sequence matches to the first 128 characters and prevents `'\s'` from accepting `'[\x1c-\x1f]'` (the so-called separator characters).** -* **Use a capital letter for negation.** +* **Use a capital letter for negation (all non-ASCII characters will be matched when used in combination with ASCII flag).** ```python '\d' == '[0-9]' # Matches decimal characters. @@ -458,8 +458,7 @@ Format | 5.6789 | '5.6789' | '5.678900' | '5.678900e+00' | '567.890000%' | | 56.789 | '56.789' | '56.789000' | '5.678900e+01' | '5678.900000%' | +--------------+----------------+----------------+----------------+----------------+ -``` -```text + +--------------+----------------+----------------+----------------+----------------+ | | {:.2} | {:.2f} | {:.2e} | {:.2%} | +--------------+----------------+----------------+----------------+----------------+ @@ -473,6 +472,7 @@ Format +--------------+----------------+----------------+----------------+----------------+ ``` * **When both rounding up and rounding down are possible, the one that returns result with even last digit is chosen. That makes `'{6.5:.0f}'` a `'6'` and `'{7.5:.0f}'` an `'8'`.** +* **This rule only works for numbers that can be represented exactly by a float (`.5`, `.25`, …).** ### Ints ```python @@ -493,7 +493,7 @@ Numbers = decimal.Decimal() # Or: Decimal((sign, digits, exponent)) ``` * **`'int()'` and `'float()'` raise ValueError on malformed strings.** -* **Decimal numbers can be represented exactly, unlike floats where `'1.1 + 2.2 != 3.3'`.** +* **All decimal numbers are stored exactly, unlike floats where `'1.1 + 2.2 != 3.3'`.** * **Precision of decimal operations is set with: `'decimal.getcontext().prec = '`.** ### Basic Functions diff --git a/index.html b/index.html index 0f25dea..cb99022 100644 --- a/index.html +++ b/index.html @@ -345,8 +345,8 @@ to_exclusive = <range>.stop
  • Argument 'flags=re.IGNORECASE' can be used with all functions.
  • Argument 'flags=re.MULTILINE' makes '^' and '$' match the start/end of each line.
  • Argument 'flags=re.DOTALL' makes dot also accept the '\n'.
  • -
  • Use r'\1' or '\\1' for backreference.
  • -
  • Add '?' after an operator to make it non-greedy.
  • +
  • Use r'\1' or '\\1' for backreference ('\1' returns a character with octal code 1).
  • +
  • Add '?' after '*' and '+' to make them non-greedy.
  • Match Object

    <str>   = <Match>.group()                      # Returns the whole match. Also group(0).
     <str>   = <Match>.group(1)                     # Returns part in the first bracket.
    @@ -358,7 +358,7 @@ to_exclusive   = <range>.stop
     

    Special Sequences

    • By default, decimal characters, alphanumerics and whitespaces from all alphabets are matched unless 'flags=re.ASCII' argument is used.
    • As shown below, it restricts special sequence matches to the first 128 characters and prevents '\s' from accepting '[\x1c-\x1f]' (the so-called separator characters).
    • -
    • Use a capital letter for negation.
    • +
    • Use a capital letter for negation (all non-ASCII characters will be matched when used in combination with ASCII flag).
    '\d' == '[0-9]'                                # Matches decimal characters.
     '\w' == '[a-zA-Z0-9_]'                         # Matches alphanumerics and underscore.
     '\s' == '[ \t\n\r\f\v]'                        # Matches whitespaces.
    @@ -421,9 +421,8 @@ to_exclusive   = <range>.stop
     ┃  5.6789      │   '5.6789'     │    '5.678900'  │ '5.678900e+00' │  '567.890000%' ┃
     ┃ 56.789       │  '56.789'      │   '56.789000'  │ '5.678900e+01' │ '5678.900000%' ┃
     ┗━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┛
    -
    -
    ┏━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━┓
    +┏━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━┓
     ┃              │  {<float>:.2}  │  {<float>:.2f} │  {<float>:.2e} │  {<float>:.2%} ┃
     ┠──────────────┼────────────────┼────────────────┼────────────────┼────────────────┨
     ┃  0.000056789 │    '5.7e-05'   │      '0.00'    │   '5.68e-05'   │      '0.01%'   ┃
    @@ -434,9 +433,11 @@ to_exclusive   = <range>.stop
     ┃  5.6789      │    '5.7'       │      '5.68'    │   '5.68e+00'   │    '567.89%'   ┃
     ┃ 56.789       │    '5.7e+01'   │     '56.79'    │   '5.68e+01'   │   '5678.90%'   ┃
     ┗━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┛
    -
    +
    +
    • When both rounding up and rounding down are possible, the one that returns result with even last digit is chosen. That makes '{6.5:.0f}' a '6' and '{7.5:.0f}' an '8'.
    • +
    • This rule only works for numbers that can be represented exactly by a float (.5, .25, …).

    Ints

    {90:c}                                   # 'Z'
     {90:b}                                   # '1011010'
    @@ -453,7 +454,7 @@ to_exclusive   = <range>.stop
     
     
    • 'int(<str>)' and 'float(<str>)' raise ValueError on malformed strings.
    • -
    • Decimal numbers can be represented exactly, unlike floats where '1.1 + 2.2 != 3.3'.
    • +
    • All decimal numbers are stored exactly, unlike floats where '1.1 + 2.2 != 3.3'.
    • Precision of decimal operations is set with: 'decimal.getcontext().prec = <int>'.

    Basic Functions

    <num> = pow(<num>, <num>)                # Or: <num> ** <num>
    diff --git a/parse.js b/parse.js
    index c77d68f..4bab160 100755
    --- a/parse.js
    +++ b/parse.js
    @@ -181,14 +181,8 @@ const DIAGRAM_4_B =
       "┃  0.56789     │   '0.56789'    │    '0.567890'  │ '5.678900e-01' │   '56.789000%' ┃\n" +
       "┃  5.6789      │   '5.6789'     │    '5.678900'  │ '5.678900e+00' │  '567.890000%' ┃\n" +
       "┃ 56.789       │  '56.789'      │   '56.789000'  │ '5.678900e+01' │ '5678.900000%' ┃\n" +
    -  "┗━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┛\n";
    -
    -const DIAGRAM_5_A =
    -  "+--------------+----------------+----------------+----------------+----------------+\n" +
    -  "|              |  {:.2}  |  {:.2f} |  {:.2e} |  {:.2%} |\n" +
    -  "+--------------+----------------+----------------+----------------+----------------+\n";
    -
    -const DIAGRAM_5_B =
    +  "┗━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┛\n" +
    +  "\n" +
       "┏━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━┓\n" +
       "┃              │  {<float>:.2}  │  {<float>:.2f} │  {<float>:.2e} │  {<float>:.2%} ┃\n" +
       "┠──────────────┼────────────────┼────────────────┼────────────────┼────────────────┨\n" +
    @@ -527,7 +521,6 @@ function updateDiagrams() {
       $(`code:contains(${DIAGRAM_2_A})`).html(DIAGRAM_2_B);
       $(`code:contains(${DIAGRAM_3_A})`).html(DIAGRAM_3_B);
       $(`code:contains(${DIAGRAM_4_A})`).html(DIAGRAM_4_B);
    -  $(`code:contains(${DIAGRAM_5_A})`).html(DIAGRAM_5_B);
       $(`code:contains(${DIAGRAM_6_A})`).html(DIAGRAM_6_B);
       $(`code:contains(${DIAGRAM_7_A})`).html(DIAGRAM_7_B);
       $(`code:contains(${DIAGRAM_8_A})`).html(DIAGRAM_8_B);