xHarbour Reference Documentation > Function Reference |
Parses a string using a regular expression and fills an array.
HB_RegExSplit( <cRegEx> , ; <cString> , ; [<lCaseSensitive>, ; [<lNewLine>] , ; [<nMaxMatches>] ) --> aSplitString
The function returns an array whose elements hold the parsing result. If no match is found, the return value is NIL.
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.
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 |
// 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
http://www.xHarbour.com