Split Method (REGEX)


 

The Split method is used to split a string into substrings using the stored regular expression in the associated PL/B REGEX object as a separator. This method uses the following format:

 

 

[label]

{object}.Split

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

 

 

[*Delimiter=]{delim}][:

 

 

[*Options=]{options}]

 

Where:

label

Optional. A Program Execution Label.

object

Required. A REGEX object previously declared.

return

Optional. A Character String Variable that contains the result as a single delimited string.

text

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

delim

Optional. A Character String Variable or literal that specifies the delimiter character.

options

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

Flags Affected: EOS, OVER, ZERO

Notes:

  1. The EOS flag is set if the returned data string is larger than the DIM variable used to receive the data.

  2. The OVER and ZERO Condition Flags are always cleared.

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

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

  5. The {delim} character defaults to "|"

  6. The {return} value contains the result as a single string with the {delim} character between separator matches.

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

  8. If no separator match is found, the {text} parameter is returned.

  9. The GetMatch method will return the last separator match.

  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_SPLIT_KEEP_EMPTY

    2

    Split method only: keep empty fields

    $REGEX_SPLIT_FIRST_ONLY

    4

    Split method only: split at the first separator

    $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 ","

      RegEx1.Split Giving S Using "a,b,c","|"

      RegEx1.Split Giving S Using ",a,,b","|",$REGEX_SPLIT_KEEP_EMPTY

      RegEx1.Split Giving S Using "a,b,c,d","|",$REGEX_SPLIT_FIRST_ONLY

 

See Also: Method Syntax, REGEX, Regular Expression Support



PL/B Language Reference