Changes between Initial Version and Version 1 of Documentation/Pattern matching

Oct 5, 2013, 8:44:11 PM (7 years ago)
Philippe Duchenne


  • Documentation/Pattern matching

    v1 v1  
     3== AmigaDOS pattern matching ==
     5The use of wildcards in patterns allows you to set up very powerful
     6searches.  The special wildcard characters are listed below.
     9  `?`   Matches any single character
     10      so Y?M matches YAM, YUM, Y@M etc.
     12  `#`   Matches zero or more occurrences of the following item
     13      so Y#AM matches YM, YAM, YAAM, YAAAM etc.
     15  `#?`  Matches anything at all (including nothing!)
     16      so #?YAM#? matches any string containing "YAM"
     18  `%`   Matches an empty string.  Not terribly useful by itself, but you could use it to find messages with blank "Subject:" headers.
     20  `()`  Round brackets are used to group characters and expressions and show how to evaluate the expression.  Use them freely!
     21      Thus #(Re!:)YAM matches YAM, Re:YAM, Re:Re:YAM ...
     23  `[]`  Square brackets are used to indicate a list of alternatives
     24      so [YAM] matches any of the single letters Y, A or M but not YAM
     26  `-`   Indicates a range, so ![0-9] matches any single digit and #![0-9] matches any integral number.
     28  `~`   Means NOT, referring to the whole expression following,
     29      so ~Re: matches any string that does not start with "Re:"
     31  `|`   Means OR, referring to the expressions either side.  You have to enclose the whole expression in round brackets:
     32      e.g.  (#?YAM#?|#?MUI#?) finds strings including either "YAM" or "MUI".
     34  `'`  Removes the meaning of a special character.  For instance,
     35      '#'? matches the literal string "#?"
     38'''WARNING! ''' It's not as easy as it looks!  For example, let's
     39construct a filter that will find references to YAM or YAM2, but will
     40disregard YAM1.  Try this one: #?YAM(~1)
     42What does this say to do?  Reading a new string from the left, look
     43for the sequence '''YAM'''.  If you find it, look at the following part: is it
     44equal to "1"?  If not, you've got a match.  The trouble is, "1.3.5" isn't
     45equal to "1" (it's too long), so YAM1.3.5 is included though we don't
     46want it.  The solution is to make it clear that the string following
     47"YAM" must not start with a "1".  So try: #?YAM(~1#?)
     49This gets rid of 1.3.5 alright, but there's still a problem:
     50sometimes, people insert a space between YAM and the version number and
     51sometimes not.  So references to '''YAM 1''' are still included.  So we must
     52say that any number of spaces may be present, like this: #?YAM# (~1#?)
     54Another case -- suppose we want to find all the strings that
     55include '''YAM''' but do not start with "Re:".  So we try: (~Re!:)YAM#?
     57This says to begin by comparing the start of the string to "Re:".
     58If we get a match, that string is discarded; if not, we look in the
     59rest of the string to find "YAM".  So what happens if the string starts
     60with "YAM"?  The first letter isn't '''R''', so the NOT condition is
     61satisfied.  But we've done the Y now, so we don't find the string '''YAM'''!
     62To sort this out, we have to explain that the string in front of "YAM"
     63may be the null string (so that's what it is for!).  Like this:
     66Question for computer buffs: what does ~((~#?YAM#?)|(~#?MUI#?))
     67mean? :-)