xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

HB_RegExAtX()

Parses a string and fills an array with parsing information.

Syntax

HB_RegExAtX( <cRegEx>         , ;
             <cString>        , ;
            [<lCaseSensitive>], ;
            [<lNewLine>]        ) --> aMatches

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).

Return

The function returns a two dimensional array. Each element of the array holds an array of three elements holding the found substring plus its start and end position. If no match is found, the return value is NIL.

Description

Function HB_RegExAtX() searches a character string using a regular expression and collects matching substrings along with their starting and ending position in a two dimensional array, which is returned. The first element of the returned array contains the whole match, while subsequent elements contain the portions of the whole match that comply with the regular expression. If the result in the first element does not match further, the returned array has one element only.

Info

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

Example

// The example matches an ISO formatted date string and displays
// the whole match and sub-matches along with theri positoins in
// the searched strings.

   PROCEDURE Main
      LOCAL cRegEx := "([0-9]{4})[-/]([0-9]{1,2})[-/]([0-9]{1,2})"
      LOCAL aDates := { "2006-9-28", ;
                        "2006/10/1", ;
                        "2006-123-1" }
      LOCAL cDate, aMatch, i

      FOR EACH cDate IN aDates
          ?
          ? "Matching:   ", cDate

          aMatch := HB_RegExAtX( cRegEx, cDate )

          IF aMatch == NIL
             ? "No match"
          ELSE
             ? "Whole match:", PadL(aMatch[1,1],10), ;
                     "Start:", PadL(aMatch[1,2], 2), ;
                       "End:", PadL(aMatch[1,3], 2)

             FOR i:=2 TO Len( aMatch )
                ? "  Sub match:", PadL(aMatch[i,1],10), ;
                        "Start:", PadL(aMatch[i,2], 2), ;
                          "End:", PadL(aMatch[i,3], 2)
             NEXT
          ENDIF
      NEXT

      ** Output:
      // Matching:    2006-9-28
      // Whole match:  2006-9-28 Start:  1 End:  9
      //   Sub match:       2006 Start:  1 End:  4
      //   Sub match:          9 Start:  6 End:  6
      //   Sub match:         28 Start:  8 End:  9
      //
      // Matching:    2006/10/1
      // Whole match:  2006/10/1 Start:  1 End:  9
      //   Sub match:       2006 Start:  1 End:  4
      //   Sub match:         10 Start:  6 End:  7
      //   Sub match:          1 Start:  9 End:  9
      //
      // Matching:    2006-123-1
      // No match
   RETURN

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