About Chandra Archive Proposer Instruments & Calibration Newsletters Data Analysis HelpDesk Calibration Database NASA Archives & Centers Chandra Science Links

Skip the navigation links
Last modified: December 2006

URL: http://cxc.harvard.edu/ciao3.4/string_match_nth.tm.html
Hardcopy (PDF): A4 | Letter
AHELP for CIAO 3.4 string_match_nth Context: slangrtl

Synopsis

Get the result of the last call to string_match

Syntax

(Integer_Type, Integer_Type) = string_match_nth(Integer_Type nth)

Description

The string_match_nth function returns two integers describing the result of the last call to string_match. It returns both the offset into the string and the length of characters matches by the nth submatch.

By convention, nth equal to zero means the entire match. Otherwise, nth must be an integer with a value 1 through 9, and refers to the set of characters matched by the nth regular expression enclosed by the pairs \(, \).

Example

Consider:

     variable matched, pos, len;
     matched = string_match("hello world", "\\([a-z]+\\) \\([a-z]+\\)", 1);
     if (matched) (pos, len) = string_match_nth(2);

This will set matched to 1 since a match will be found at the first position, pos to 6 since w is offset 6 characters from the beginning of the string, and len to 5 since "world" is 5 characters long.

The position offset is not affected by the value of the offset parameter to the string_match function. For example, if the value of the last parameter to the string_match function had been 3, pos would still have been set to 6.

Note also that string_match_nth returns the offset from the beginning of the string and not the position of the match.

Hardcopy (PDF): A4 | Letter
Last modified: December 2006



The Chandra X-Ray Center (CXC) is operated for NASA by the Smithsonian Astrophysical Observatory.
60 Garden Street, Cambridge, MA 02138 USA.    Email: cxcweb@head.cfa.harvard.edu
Smithsonian Institution, Copyright © 1998-2004. All rights reserved.