prev| toc| next
 

2.1.6 Pattern Matching and Output Types

As indicated, the @find command can be used to locate items with a given name. For more flexible searches, you can use pattern matching (a limited version of regular expressions) to find objects whose name matches a certain pattern, rather than matching the name string literally. A pattern consists of logical and grouping operators, wildcard characters, and/or literal characters. @Find —and the related search commands @owned, @contents, and @entrances — can be used with a subset of standard regular expression conventions, and additional parameters that specify `output types' (parameters for values such as memory used, time since used or modified, etc.)

Suppose that you have created a Coral Reef area, with interesting scenery and games: players try to avoid sharks, wrestle octopi, and find sunken treasure before they run out of breath and are forced to return to the surface. To use the rooms and games, a player must have a snorkle. You have set up a `make snorkle' action linked to an M2 program that changes an object into a snorkle (it sets all the properties used by your games). And, you have a Snorkle Rental Booth: a room where can people rent snorkles or read `The Complete Book of Snorkles' and `Field Guide to the Lesser Coral Reef' (help on how to use the area). The reef rooms have names like `Coral Reef, Sandy Wash' and `Coral Reef, Moray's Lair'. Occassionally, you need to find these objects... to recall and update your snorkles or track down your wandering shark-bot, for example.

You can use literal matches to find objects whose name includes the string you are trying to match. Matching is not case-sensitive.

====================================
> @find complete book
  The Complete Book of Snorkles(#811SJ)
  1 objects found.

> @find coral reef
  Field Guide to the Lesser Coral Reef(#810SJ)
  Coral Reef, Sandy Wash(#802RJ)
  Coral Reef, Moray's Lair(#805RJ)
  Coral Reef, Near the Surface(#809RJ)
  Coral Reef, Weed-Shrouded Cave(#812RJ)
  Coral Reef, Sunken Hull(#815RJ)
  Coral Reef, Dark Cave(#817RJ)
  <etc.>
  <etc.>
  ***End of List***
  16 objects found.
====================================

The * and ? wildcard characters allow you to search for names that match a pattern, rather than a literal string. The * asterix wildcard (sometimes called a `glob') matches any zero or more characters; the ? question mark matches any single character.

You could find your two cave rooms in the coral reef area (and leave out other cave rooms you might have) by beginning putting a glob between `Coral' and `Cave'.

====================================
> @find coral*cave
  Coral Reef, Weed-Shrouded Cave(#812RJ)
  Coral Reef, Dark Cave(#817RJ)
  ***End of List***
  2 objects found.
====================================

You could find all the reef rooms, leaving out the book `Field Guide to the Lesser Coral Reef', by searching for `reef' followed by a ? question mark, which would require that there be at least one character after the string `reef'.

====================================
> @find reef?
  Coral Reef, Sandy Wash(#802RJ)
  Coral Reef, Moray's Lair(#805RJ)
  Coral Reef, Near the Surface(#809RJ)
  <etc.>
  <etc.>
  ***End of List***
  15 objects found.
====================================

The {curly braces} grouping operators delimit word patterns. To find all your snorkle objects and the `make snorkle' action, but omit `The Complete Book of Snorkles', you could delimit `snorkle' as a word, and not simply a string.

====================================
> @find {snorkle}
  Snorkle Rental Booth(#856RJ)
  make snorkle(#857ED)
  Snorkle 1(#854)
  Snorkle 2(#859)
  Snorkle 3(#881)
  Snorkle 4(#882)
  Snorkle 5(#883)
  Snorkle 6(#884)
  Snorkle 7(#885)
  Snorkle 8(#886)
  Snorkle 9(#887)
  Snorkle 10(#888)
  Snorkle 11(#889)
  Snorkle 12(#890)
  ***End of List***
  13 objects found.
====================================

One can search for objects whose names include words from a group of valid words by separating the words with the `or' operator, a | vertical bar. For example, you could find all objects that include the words `sunken' or `surface'.

====================================
> @find {sunken|surface}
  Coral Reef, Near the Surface(#809RJ)
  Coral Reef, Sunken Hull(#815RJ)
  ***End of List***
  2 objects found.
====================================

The [square brackets] grouping operators delimit character groups or ranges or characters.

A group of characters in square brackets are treated as valid single characters. A find for `coral reef, [wdn]' would find the coral reef rooms with either `w', `d', or `n' following the string `coral reef, `.

====================================
> @find coral reef, [wdn]
  Coral Reef, Near the Surface(#809RJ)
  Coral Reef, Weed-Shrouded Cave(#812RJ)
  Coral Reef, Dark Cave(#817RJ)
  ***End of List***
  3 objects found.
====================================

Instead of typing each valid character, you can also designate a range of valid characters, such as [0-9], [a-z], or [A-Z]. You could find all your snorkle objects, which all have a numeric character following the string `Snorkle `, by using [0-9] as the range of characters.

====================================
> @find snorkle [0-9]
  Snorkle 1(#854)
  Snorkle 2(#859)
  Snorkle 3(#881)
  Snorkle 4(#882)
  Snorkle 5(#883)
  Snorkle 6(#884)
  Snorkle 7(#885)
  Snorkle 8(#886)
  Snorkle 9(#887)
  Snorkle 10(#888)
  Snorkle 11(#889)
  Snorkle 12(#890)
  ***End of List***
  12 objects found.
====================================

Note that the [square brackets] delimit character ranges, not numeric ranges. A find for `snorkles [1-12]' won't work... or won't work as one might intend. It finds all objects with either characters in the range of `1 to 1' or the character `2' following the string `snorkles `.

====================================
> @find snorkle [1-12]
  Snorkle 1(#8454)
  Snorkle 2(#8459)
  snorkle 10(#8488)
  snorkle 11(#8489)
  snorkle 12(#8490)
  ***End of List***
  5 objects found.
====================================

prev| toc| top| next