xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

HB_RegExSplit()

Parses a string using a regular expression and fills an array.

Syntax

HB_RegExSplit( <cRegEx>        , ;
               <cString>       , ;
              [<lCaseSensitive>, ;
              [<lNewLine>]     , ;
              [<nMaxMatches>]    ) --> aSplitString

Arguments

<cRegEx>
This is a character string holding the search pattern as a literal regular expression. Alternatively, the return value of HB_RegExComp() can be used.
<cString>
This is the character string being searched for a match.
<lCaseSensitive>
This parameter defaults to .T. (true) so that a case sensitive search is performed. Passing .F. (false) results in a case insensitive search.
<lNewLine>
This parameter defaults to .F. (false).
<nMaxMatches>
This is a numeric value indicating the maximum number of matches to return. The default value is zero which returns all matches.

Return

The function returns an array whose elements hold the parsing result. If no match is found, the return value is NIL.

Description

Function HB_RegExSplit() scans a character string for substrings matching a regular expression. All matched substrings are removed while the remaining strings are collected and returned in an array.

Info

See also:HAS, HB_AtX(), HB_RegEx(), HB_RegExAll(), HB_RegExComp(), HB_RegExReplace(), LIKE
Category: Character functions , Regular expressions , xHarbour extensions
Source:rtl\regex.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example demonstrates the result of parsing a text string
// using different regular expressions.

   PROCEDURE Main
      LOCAL cRegEx := "[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}"
      LOCAL cText  := "Send your request to info@xharbour.com " + ;
                      "for more information"
      LOCAL aResult, cEmail

      CLS

      ? "----- words in text -----"
      aResult := HB_RegExSplit( " ", cText )
      AEval( aResult, {|c| QOut(c) } )

      cEmail := HB_AtX( cRegEx, cText, .F. )
      ?
      ? "----- email address -----"
      ? cEMail

      aResult := HB_RegExSplit( "[.@]", cEMail )

      ?
      ? "----- email components --"
      AEval( aResult, {|c| QOut(c) } )

      ** Output
      // ----- words in text -----
      // Send
      // your
      // request
      // to
      // info@xharbour.com
      // for
      // more
      // information
      //
      // ----- email address -----
      // info@xharbour.com
      //
      // ----- email components --
      // info
      // xharbour
      // com
   RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe