View on GitHub

IRAF Community Distribution

IRAF maintained by the community

Home | Installation | Packages | X11IRAF | PyRAF | Forum

script tricks: pattern matching in strings

Frank Valdes wrote on May 23, 2000

Q:  Is there a way to identify (and constrain a search for) characters
in a string? Eg similar to what is possible in STSDAS table tools?

I need something of the kind:

if( substr(spec,s,i) == "{a-z}") do this

ie, identify the position of an entry in the string with this range
in characters (and ignore case in the process; for the above syntax).


A:  There is a way to do what you want.  The CL string comparison
operator does not provide "pattern matching".  So you need to use a
task that does.  The appropriate task is MATCH.  To use it in a script
do something like

str = ""
print (substr(spec,s,i)) | match ("{a-z}") | scan (str)
if (str != "") {
   do this
}

Note that str has to be declared as struct if you want to have spaces
in the string.  Read the help for MATCH to find the pattern operators
allowed.  You can also use "printf" but be sure to terminate the format
string with a new line:

printf ("%s\n", substr(spec,s,i)) | ...

Last post on May 23, 2000