Wildcards

Prev Next

Introduction

B4P supports wildcards which enables for more effective search and comparison functions as they enable pattern matching with concepts such as

  • Begins with ...
  • Ends with ...
  • Contains ...
  • Multiple patterns separated by commas ...

Wildcards are used, amongst others, in following functionalities:

Unless specified otherwise (like in searching files), wildcard symbols in strings will only work if specified as softquoted strings (e.g. text inside single quotation marks).

Symbol Meaning Example Explanation

Plaholder for any number of characters (incl. 0) A*
*s
*-*
A*E
Begins with 'A'
Ends with 's'
Contains '-'
Begins with 'A' and ends with 'E'

~

Placeholder for any number of letters (incl. 0)
Foreign (non-ANSI) characters are accepted here, too.
~ Street Expecting a name for the street (letters only)
& Placeholder for any number of numeric digits 0..9 & kg Expects a number of any size before ' kg'
? Placeholder for exactly 1 character ???
A?
Contains 3 characters of choice
A follwed by 1 character of choice
# Placeholder for exactly 1 numeric digit 0..9 ###-##-#### Expect a social security number (U.S. number format)
^ Placeholder for exactly 1 alphanumeric character
Foreign (non-ANSI) characters are accepted here, too.
^^^ Expect 3 letters
, Defines additional pattern to compare A*,B*,C* May begin with A, B or C.

For searching files using directory and file functions, the wildcards are limited to * and ?.

Programming example

       table initialize ( demo wildcards,
       { { Target string, '*', '~', 'A*', '&', 'Zip*#####', '??t', '*t', 'A*,B*,C*' },
           Hello,
           1234,
           12345,              // Column headers contain wildcard symbols
           Zip 12010,          // 1st column contain target strings to compare with these patterns
           Cat,                // The blank rows will be filled in with comparison results
           Bat,                // 'true' and 'false'.
           halt } );

       table configure( demo wildcards, read numerals, no ); // Read numbers from tables as strings

       table process( demo wildcards,
           for (c[] = 1, c[] < table row width( demo wildcards, 0 ), c[]++ )
           {
               [c[]]      = [0]      = soft( [c[], 0 ] ); // Compare and write the result
               // Current   Column   Compared with corresponding header name above
               // column    zero
           } );

       table list( demo wildcards );

Output 01

    0 : Target string | *    | ~     | A*    | &     | Zip*##### | ??t   | *t    | A*,B*,C*
    1 : Hello         | true | true  | false | false | false     | false | false | false   
    2 : 1234          | true | false | false | true  | false     | false | false | false   
    3 : 12345         | true | false | false | true  | false     | false | false | false   
    4 : Zip 12010     | true | false | false | false | true      | false | false | false   
    5 : Cat           | true | true  | false | false | false     | true  | true  | true    
    6 : Bat           | true | true  | false | false | false     | true  | true  | true    
    7 : halt          | true | true  | false | false | false     | false | true  | false   

Try it yourself: Open LAN_Features_wildcards.b4p in B4P_Examples.zip. Decompress before use.