Pattern Expansion

From Derivative
Jump to: navigation, search

Pattern Expansion takes a short string and generates a longer string from it. Pattern Replacement uses Pattern Expansion, along with having some of it's own syntax on-top of Pattern Expansion.

Expansion is done by using putting the data to expand into []. Valid syntax is

  • [<letters>] - Where letters is one or more letters (not numbers), each of which will be split out into it's own result.
  • [<startNumber>-<endNumber>] - Where startNumber and endNumber form a range of numbers. A result will be created for each number in the range.
  • [<startNumber>-<endNumber>:<increment>] - Similar to the previous one, but increment allows for skipping numbers in the range, so less results are created, and numbers are skipped.

Note that the [1,2,3] syntax available in Pattern Matching is not available here.

Each expansion will be expanded against every possible other expansion in the string. So one expansion with 2 results followed by one with 3 results, will result in a final result containing 6 results.

For example, the pattern:

[tr][xyz]

expands to:

 tx ty tz rx ry rz

While the pattern:

chan[1-11:2]

expands to:

chan1 chan3 chan5 chan7 chan9 chan11

The opposite of Pattern Expansion is "Pattern Matching" where you are looking for patterns in a longer string or a large set of strings.

Pattern expansion occurs in: