Pattern Expansion

From Derivative
Jump to navigation Jump to search

Pattern Expansion takes a short string and expands it to generate a longer string of individual elements. Example: chan[1-3] generates chan1 chan2 chan3.

Pattern Replacement uses Pattern Expansion, along with having some of it's own syntax on-top of Pattern Expansion. The opposite of Pattern Expansion is "Pattern Matching" where you are looking for patterns in a longer string or a large set of strings.

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.

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

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

Pattern expansion occurs in:

Note: See tdu.expand() in Tdu_Module

Note: To expand a list of operators that is in a parameter type that is a list of operators, see .evalOPs() in Par Class

See also Pattern Replacement, Pattern Matching.