| xHarbour Reference Documentation > Function Reference |
![]() |
![]() |
![]() |
Tests if a string contains a substring using a regular expression
HB_RegExMatch( <cRegEx> , ;
<cString> , ;
[<lCaseSensitive>], ;
[<lNewLine>] ) --> lFound
The function returns .T. (true), when <cString> contains a substring matching the regular expression <cRegEx>, otherwise .F. (false) is returned.
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.
| 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 |
// 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
http://www.xHarbour.com