Skip to content

Commit 8fcc1a6

Browse files
authored
FAQ entry for #351 (#958)
1 parent 472b42d commit 8fcc1a6

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

docs/src/special-symbols-and-formatting.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,19 @@ b it is!
165165
c is it ...
166166
</pre>
167167

168-
The `ssub` function exists precisely for this reason: so you don't have to escape anything.
168+
The [`ssub`](reference-dsl-builtin-functions.md#ssub) function exists precisely for this reason: so you don't have to escape anything.
169+
170+
## How to apply math to regex output?
171+
172+
* Use parentheses for capture groups
173+
* Use `\1`, `\2`, etc. to refer to the captures
174+
* The matched patterns are strings, so cast them to `int` or `float`
175+
176+
See also the [page on regular expressions](reference-main-regular-expressions.md).
177+
178+
<pre class="pre-highlight-in-pair">
179+
<b>echo "a=14°45'" | mlr put '$a =~"^([0-9]+)°([0-9]+)" {$degrees = float("\1") + float("\2") / 60}'</b>
180+
</pre>
181+
<pre class="pre-non-highlight-in-pair">
182+
a=14°45',degrees=14.75
183+
</pre>

docs/src/special-symbols-and-formatting.md.in

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,16 @@ GENMD-RUN-COMMAND
8989
mlr --oxtab put '$c = ssub($a, "?"," ...")' data/question.dat
9090
GENMD-EOF
9191

92-
The `ssub` function exists precisely for this reason: so you don't have to escape anything.
92+
The [`ssub`](reference-dsl-builtin-functions.md#ssub) function exists precisely for this reason: so you don't have to escape anything.
93+
94+
## How to apply math to regex output?
95+
96+
* Use parentheses for capture groups
97+
* Use `\1`, `\2`, etc. to refer to the captures
98+
* The matched patterns are strings, so cast them to `int` or `float`
99+
100+
See also the [page on regular expressions](reference-main-regular-expressions.md).
101+
102+
GENMD-RUN-COMMAND
103+
echo "a=14°45'" | mlr put '$a =~"^([0-9]+)°([0-9]+)" {$degrees = float("\1") + float("\2") / 60}'
104+
GENMD-EOF

todo.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ RELEASES
33
* plan 6.1.0
44
o unsparsify -f CSV by default -- ? into CSV record-writer -- ? caveat that record 1 controls all ...
55
o mlr join --left-fields a,b,c
6-
o several needs-doc issues
7-
https://github.com/johnkerl/miller/issues?q=is%3Aissue+is%3Aopen+label%3Aneeds-documentation
86
o fmt/unfmt/regex doc
97
o FAQ/examples reorg
108
? ??? for doc-string contents search -- ? & mlr help namegoeshere foo ...
119

10+
o several needs-doc issues
11+
https://github.com/johnkerl/miller/issues?q=is%3Aissue+is%3Aopen+label%3Aneeds-documentation
12+
echo "a=14°20" | mlr put '$out=sub($a,"^([0-9]+)°([0-9]+)$","\1\2")'
13+
1214
k strptime/882
1315
k fmtifnum, & recursive fmtnum/fmtifnum
1416
k unicode string literals
@@ -26,6 +28,9 @@ RELEASES
2628
k ?foo and ??foo @ repl help
2729
k doc-improves
2830

31+
d all-contribs check before release
32+
> release notes in particular Poshi derekmahar aborruso
33+
2934
* plan 6.2.0
3035
! extended field accessors for #763 and #948 (positional & json.nested)
3136
! strict mode

0 commit comments

Comments
 (0)