• Tutorials

  • Home
  • GPDL $WIGGLE

    DungeonCraft Help Home

    Here is a neat little function. It allows you to access the matched sub-expressions from a previous$GREP (or $GCASE) statement.

    Each time $GREP (or $GCASE) is executed it leaves behind a list of all the matched subexpressions that were matched in the source string. These are the subexpressions that can be referenced within the $GREP itself as 'back references'.

    The parameter to $WIGGLE is an integer that specifies which substring one is interested in. The number start at 1 for sub-expressions. Zero means the entire match expression. But an example will make this all very much clearer.

    Let us say that the source string is "Dungeon Craft is a neat thing". And that the search string is

     "(.*)eon.*(n.*n)".  

    Then the search succeeds because it finds the string "Dungeon Craft is a neat thin". The first parenthesized expression matched "Dung". And the second parenthesized expression in the search string matched "neat thin". So:

    $WIGGLE(0) will return "Dungeon Craft is a neat thin"
    $WIGGLE(1) will return "Dung"
    $WIGGLE(2) will return "neat thin"

    We could have been more clever at generating an amusing example.