Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@
"regexp",
"sequences"
],
"status": "wip"
"status": "beta"
},
{
"slug": "lap-leaderboard",
Expand Down
25 changes: 15 additions & 10 deletions exercises/concept/ledger-lookout/.docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,28 @@ spot **without** making those characters part of the match. It is
"zero-width": what it tests is not included in the result.

```
(?=...) ! lookahead: ... must follow
(?!...) ! negative lookahead: ... must NOT follow
(?<=...) ! lookbehind: ... must come before
(?=...) ! lookahead: ... must follow
(?!...) ! negative lookahead: ... must NOT follow
(?<=...) ! lookbehind: ... must come before
(?<!...) ! negative lookbehind: ... must NOT come before
```

Lookaround is *selective* — the same characters match or not depending
on what sits beside them. A plain `\d+` grabs every number; the lookbehind
and lookahead keep only those with the right neighbour:

```factor
USING: regexp ;

"spent $100 and $25" R/ (?<=\$)\d+/ all-matching-subseqs .
! => { "100" "25" } (digits that follow a $; the $ is left out)
"3 for $10 or 10 for $30" R/ \d+/ all-matching-subseqs .
! => { "3" "10" "10" "30" } (every number)

"up 5% then 12%" R/ \d+(?=%)/ all-matching-subseqs .
! => { "5" "12" } (digits that come right before a %)
```
"3 for $10 or 10 for $30" R/ (?<=\$)\d+/ all-matching-subseqs .
! => { "10" "30" } (only the prices — the bare 3 and 10 drop)

Lookaround is how you say "the part I want, recognised by what
surrounds it" — exactly what capture groups do elsewhere.
"buy 2 at 15% off, 4 at 30% off" R/ \d+(?=%)/ all-matching-subseqs .
! => { "15" "30" } (only the discounts — the bare 2 and 4 drop)
```

## Options

Expand Down
Loading