xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

HB_RegExMatch()

Tests if a string contains a substring using a regular expression

Syntax

HB_RegExMatch( <cRegEx>         , ;
               <cString>        , ;
              [<lCaseSensitive>], ;
              [<lNewLine>]        ) --> lFound

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 match is performed. Passing .F. (false) results in a case insensitive match.
<lNewLine>
This parameter defaults to .F. (false).

Return

The function returns .T. (true), when <cString> contains a substring matching the regular expression <cRegEx>, otherwise .F. (false) is returned.

Description

HB_RegExMatch() is a simple regular expression function that tests if a text string contains a substring matching the regular expression. It is similar to the HAS operator.

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 tests if a text string contains an eMail address.
// The search is case insensitive although the RegEx defines
// character classes only with upper case letters.

   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"

      IF HB_RegExMatch( cRegEx, cText, .F. )
         ? "Text contains eMail address"
      ELSE
         ? "Text contains no eMail address"
      ENDIF
   RETURN

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