Count Method (REGEX)


 

The Count method is used to obtain the number of matches found in a character string. The method uses the stored regular expression in the associated PL/B REGEX object. This method uses the following format:

 

 

[label]

{object}.Count

[GIVING {return}] USING [*Text=]{text}[:

 

 

[*Options=]{options}]

 

Where:

label

Optional. A Program Execution Label.

object

Required. A REGEX object previously declared.

return

Optional. A Numeric Variable that returns the number of matches found using the compiled pattern, including empty matches.

text

Required. A Character String Variable or literal that specifies the character string to examine.

options

Optional. A decimal number or Numeric Variable that has a bit mask value described below.

Flags Affected: EOS, OVER, ZERO

Notes:

  1. If the value returned is zero, the ZERO Condition Flag is set.

  2. The OVER flag is set TRUE if the 'return' variable is too small and cannot contain the 'return' value without being truncated. Otherwise, the OVER flag is set to FALSE.

  3. The EOS flag is always cleared.

  4. The {text} parameter contains the character string to be searched.

  5. The search pattern used is the currently compiled pattern.

  6. The {return} value is the count of matches in the character string.

  7. A zero-length match counts as a match.

  8. If no matches are found the GetMatch method will return an empty string.

  9. If a match is found the GetMatch method will return the last match found.

  10. The {options} bit mask values found in plbmeth.inc are defined as follows:

  11.  

    Equate

    Value

    Description

    $REGEX_OPT_NOCASE

    1

    Case-insensitive (ASCII A-Z only)

    $REGEX_OPT_MULTILINE

    8

    ^ and $ also match at line breaks

    $REGEX_OPT_DOTALL

    16

    . also matches CR and LF

    $REGEX_OPT_NOTEMPTY

    32

    Reject empty (zero-length) matches

  12. The {options} given to Compile method also apply.

 

Example 1:

 

      RegEx1.Compile Giving N Using "i"

      RegEx1.Count Giving N Using "This is Alice"

 

 

See Also: Method Syntax, REGEX, Regular Expression Support



PL/B Language Reference