Previous Page | Next Page

Functions and CALL Routines

CALL PRXNEXT Routine



Returns the position and length of a substring that matches a pattern, and iterates over multiple matches within one string.
Category: Character String Matching
Restriction: Use with the PRXPARSE function.
Interaction: When invoked by the %SYSCALL macro statement, CALL PRXNEXT removes the quotation marks from arguments. For more information, see Using CALL Routines and the %SYSCALL Macro Statement.

Syntax
Arguments
Details
Comparisons
Examples
See Also

Syntax

CALL PRXNEXT (regular-expression-id, start, stop, source, position, length);

Arguments

regular-expression-id

specifies a numeric variable with a value that is the identification number that is returned by the PRXPARSE function.

start

is a numeric variable that specifies the position at which to start the pattern matching in source. If the match is successful, CALL PRXNEXT returns a value of position + MAX(1, length). If the match is not successful, the value of start is not changed.

stop

is a numeric constant, variable, or expression that specifies the last character to use in source. If stop is -1, then the last character is the last non-blank character in source.

source

specifies a character constant, variable, or expression that you want to search.

position

is a numeric variable with a returned value that is the position in source at which the pattern begins. If no match is found, CALL PRXNEXT returns zero.

length

is a numeric variable with a returned value that is the length of the string that is matched by the pattern. If no match is found, CALL PRXNEXT returns zero.


Details

The CALL PRXNEXT routine searches the variable source with a pattern. It returns the position and length of a pattern match that is located between the start and the stop positions in source. Because the value of the start parameter is updated to be the position of the next character that follows a match, CALL PRXNEXT enables you to search a string for a pattern multiple times in succession.

For more information about pattern matching, see Pattern Matching Using Perl Regular Expressions (PRX).


Comparisons

The Perl regular expression (PRX) functions and CALL routines work together to manipulate strings that match patterns. To see a list and short description of these functions and CALL routines, see the Character String Matching category in Functions and CALL Routines by Category.


Examples

The following example finds all instances of cat, rat, or bat in a text string.

data _null_;
   ExpressionID = prxparse('/[crb]at/');
   text = 'The woods have a bat, cat, and a rat!';
   start = 1;
   stop = length(text);

      /* Use PRXNEXT to find the first instance of the pattern, */
      /* then use DO WHILE to find all further instances.       */
      /* PRXNEXT changes the start parameter so that searching  */
      /* begins again after the last match.                     */
   call prxnext(ExpressionID, start, stop, text, position, length);
      do while (position > 0);
         found = substr(text, position, length);
         put found= position= length=;
         call prxnext(ExpressionID, start, stop, text, position, length);
      end;
run;

The following lines are written to the SAS log:

   found=bat position=18 length=3
   found=cat position=23 length=3
   found=rat position=34 length=3


See Also

Functions and CALL routines:

CALL PRXCHANGE Routine

CALL PRXDEBUG Routine

CALL PRXFREE Routine

CALL PRXPOSN Routine

CALL PRXSUBSTR Routine

CALL PRXCHANGE Routine

PRXCHANGE Function

PRXPAREN Function

PRXMATCH Function

PRXPARSE Function

PRXPOSN Function

Previous Page | Next Page | Top of Page