|
| 1 | +--- |
| 2 | +sheet: Sheet |
| 3 | +--- |
| 4 | +# Matching and Transforming Strings with Regex |
| 5 | + |
| 6 | +Some commands for selecting, searching, and transforming data, accept a regular expression as input. |
| 7 | + |
| 8 | +## Select Rows |
| 9 | + |
| 10 | +- {help.commands.select-col-regex} |
| 11 | +- {help.commands.select-cols-regex} |
| 12 | + |
| 13 | +- {help.commands.unselect-col-regex} |
| 14 | +- {help.commands.unselect-cols-regex} |
| 15 | + |
| 16 | +## Search |
| 17 | + |
| 18 | +- {help.commands.go-col-regex} |
| 19 | + |
| 20 | +- {help.commands.search-col} |
| 21 | +- {help.commands.search-cols} |
| 22 | + |
| 23 | +- {help.commands.searchr-col} |
| 24 | +- {help.commands.searchr-cols} |
| 25 | + |
| 26 | +- {help.commands.search-next} |
| 27 | +- {help.commands.searchr-next} |
| 28 | + |
| 29 | +- {help.commands.search-keys} |
| 30 | + |
| 31 | +## Substitution |
| 32 | + |
| 33 | +- {help.commands.setcol-regex-subst} |
| 34 | +- {help.commands.setcol-regex-subst-all} |
| 35 | + |
| 36 | +`Tab` to move between `search` and `replace` inputs. |
| 37 | +An empty `replace` removes the matching string. |
| 38 | + |
| 39 | +# Column Creation |
| 40 | + |
| 41 | +- {help.commands.addcol-regex-subst} |
| 42 | +- {help.commands.addcol-split} |
| 43 | +- {help.commands.addcol-capture} |
| 44 | + |
| 45 | +## Examples |
| 46 | + |
| 47 | +### Split |
| 48 | + |
| 49 | +Sample input sheet **sales**: |
| 50 | + |
| 51 | + date price |
| 52 | + ---------- ----- |
| 53 | + 2024-09-01 30 |
| 54 | + 2024-09-02 28 |
| 55 | + 2024-09-03 100 |
| 56 | + |
| 57 | +1. [:code]:[/] (`addcol-split`) on **date** column, followed by `-` to split on hyphens. |
| 58 | + |
| 59 | + date date_re price |
| 60 | + ---------- ---------------- ----- |
| 61 | + 2024-09-01 [3] 2024; 09; 01 30 |
| 62 | + 2024-09-02 [3] 2024; 09; 02 28 |
| 63 | + 2024-09-03 [3] 2024; 09; 03 100 |
| 64 | + |
| 65 | +Note that the results in the `date_re` column are lists of length 3. |
| 66 | + |
| 67 | +2. [:code]([/] (`expand-col`) to expand a column with lists into multiple columns with the list elements. |
| 68 | + |
| 69 | + date date_re[0] date_re[1] date_re[2] price |
| 70 | + ---------- ---------- ---------- ---------- ----- |
| 71 | + 2024-09-01 2024 09 01 30 |
| 72 | + 2024-09-02 2024 09 02 28 |
| 73 | + 2024-09-03 2024 09 03 100 |
| 74 | + |
| 75 | +### Substitution |
| 76 | + |
| 77 | +1. On the **date** column, [:code]*[/] (`addcol-regex-subst`) and type `-`, then `Tab` to "replace" and type `,`. Then `Enter` to replace all `-` with `,`. |
| 78 | + |
| 79 | + date date_re price |
| 80 | + ---------- ---------- ----- |
| 81 | + 2024-09-01 2024,09,01 30 |
| 82 | + 2024-09-02 2024,09,02 28 |
| 83 | + 2024-09-03 2024,09,03 100 |
| 84 | + |
| 85 | +### Capture |
| 86 | + |
| 87 | +1. On the **date** column, [:code];[/] (`addcol-capture`) and type `(\d\d\d\d)` to capture and pull out the year. |
| 88 | + |
| 89 | + date date_re price |
| 90 | + ---------- -------- ----- |
| 91 | + 2024-09-01 [1] 2024 30 |
| 92 | + 2024-09-02 [1] 2024 28 |
| 93 | + 2024-09-03 [1] 2024 100 |
| 94 | + |
| 95 | +Note that the results in the `date_re` column are lists of length 1. |
| 96 | + |
| 97 | +2. [:code]([/] (`expand-col`) to expand a column with lists into multiple columns with the list elements. |
| 98 | + |
| 99 | + date date_re[0] price |
| 100 | + ---------- ---------- ----- |
| 101 | + 2024-09-01 2024 30 |
| 102 | + 2024-09-02 2024 28 |
| 103 | + 2024-09-03 2024 100 |
0 commit comments