NRAO Home > CASA > CASA Cookbook and User Reference Manual
2.3.1.1 String Matching

String matching can be done in three ways. Any component of a comma separated list that cannot be parsed as a number, a number range, or a physical quantity is treated as a regular expression or a literal string. If the string does not contain the characters ’*’, {, }or ’?’, it is treated as a literal string and used for exact matching. If any of the above mentioned characters are part of the string, they are used as a regular expression. As a result, for most cases, the user does not need to supply any special delimiters for literal strings and/or regular expressions. For example:

  field = ’3’     # match field ID 3 and not select field named "3C286".  
 
  field = ’3*’    # used as a pattern and matched against field names. If  
                  # names like "3C84", "3C286", "3020+2207" are found,  
                  # all will match. Field ID 3 will not be selected  
                  # (unless of course one of the above mentioned field  
                  # names also correspond to field ID 3!).  
 
  field = ’30*’   # will match only with "3020+2207" in above set.

However if it is required that the string be matched exclusively as a regular expression, it can be supplied within a pair of ’/’ as delimiters (e.g. ’/.+BAND.+/’). A string enclosed within double quotes (’"’) is used exclusively for pattern matching (patterns are a simplified form of regular expressions - used in most UNIX commands for string matching). Patterns are internally converted to equivalent regular expressions before matching. See the Unix command "info regex", or visit http://www.regular-expressions.info, for details of regular expressions and patterns.

Strings can include any character except the following:

     ’,’   ’;’   ’"’  ’/’   NEWLINE

(since these are part of the selection syntax). Strings that do not contain any of the characters used to construct regular expressions or patterns are used for exact matches. Although it is highly discouraged to have name in the MS containing the above mentioned reserved characters, if one does choose to include the reserved characters as parts of names etc., those names can only be matched against quoted strings (since regular expression and patterns are a super-set of literal strings – i.e., a literal string is also a valid regular expression).

This leaves ’"’, ’*’, {, }or ’?’ as the list of printable character that cannot be part of a name (i.e., a name containing this character can never be matched in a MSSelection expression). These will be treated as pattern-matching even inside double double quotes (’" "’). There is currently no escape mechanism (e.g. via a backslash).

Some examples of strings, regular expressions, and patterns:


More information about CASA may be found at the CASA web page

Copyright © 2010 Associated Universities Inc., Washington, D.C.

This code is available under the terms of the GNU General Public Lincense


Home | Contact Us | Directories | Site Map | Help | Privacy Policy | Search