xHarbour Reference Documentation > Function Reference |
Locates a substring within a character string based on a regular expression.
HB_AtX( <cRegEx> , ; <cString> , ; [<lCaseSensitive>], ; [@<nStart>] , ; [@<nLen>] ) --> cFoundString
The function returns the first substring contained in <cString> that matches the regular expression <cRegEx>. If no match is found, the return value is NIL.
Function HB_AtX() searches a character string for matching regular expression and returns the found substring. It is a simple pattern matching function which searches and extracts only the first occurance of a substring and optionally returns its position and size in the searched string when <nStart> and <nLen> are passed by reference.
See also: | At(), HB_RegEx(), HB_RegExAll(), HB_RegExSplit(), RAt(), SubStr() |
Category: | Character functions , Regular expressions , xHarbour extensions |
Source: | rtl\regex.c |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// The example extracts an eMail address from a text string. // 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" LOCAL cEmail, nStart, nLen cEmail := HB_AtX( cRegEx, cText, .F., @nStart, @nLen ) ? cEmail // result: info@xharbour.com ? nStart // result: 22 ? nLen // result: 17 RETURN
http://www.xHarbour.com