xHarbour Reference Documentation > Operator Reference xHarbour Developers Network  

LIKE

Compares a character string with a regular expression.

Syntax

<cString> LIKE <cRegEx>

Arguments

<cString>
This is the character string being compared.
<cRegEx>
This is a character string holding the comparison rule as a literal regular expression. Alternatively, the return value of HB_RegExComp() can be used.

Description

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.

Info

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

Example

// 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

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