xHarbour Reference Documentation > Operator Reference |
Compares a character string with a regular expression.
<cString> LIKE <cRegEx>
The LIKE operator compares the character string <cString> with the regular expression <cRegExp>. If the string matches the regular expression, the result of the operator is .T. (true). When no match is given, the result is .F. (false).
If the LIKE operator is applied often in a search routine with the same regular expression, a literal regular expression <cRegEx> can be compiled with HB_RexExComp() to speed up operations.
See also: | $, AScan(), IN, HAS, HB_RegEx(), HB_RegExComp(), HScan() |
Category: | Character operators , Comparison operators , Operators , Regular expressions , xHarbour extensions |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// The example uses a regular expression to detect if a character // string is a valid eMail address. PROCEDURE Main LOCAL cRegEx := "ˆ[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$" LOCAL aString LOCAL cEMail aString := { "info@xHarbour.com" , ; "info_xHarbour.com" , ; "info@xHarbour,com" , ; "Mail to info@xHarbour.com" } FOR EACH cEMail IN aString IF cEMail LIKE cRegEx ? cEMail, "is valid" ELSE ? cEMail, "is not valid" ENDIF NEXT ** Output: // info@xHarbour.com is valid // info_xHarbour.com is not valid // info@xHarbour,com is not valid // Mail to info@xHarbour.com is not valid RETURN
http://www.xHarbour.com